LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-26-2008, 09:46 AM   #1
jimbo1954
Member
 
Registered: Oct 2006
Location: High Wycombe, Bucks, UK.
Distribution: Debian and Fedora Core in equal measure
Posts: 264

Rep: Reputation: 33
Running sftp under Expect and transfers fail


Guys,
I have a Linux Server (Debian 2.6.18-6-686)from which I want to sftp files to an external (unknown other than some form of windows)server.

If I issue the commands interactively, I get something like this (copied from the screen directly and anonomized):

DEBIAN:/usr/autoftp/scripts# sftp UserName@www.xxx.yyy.zzz
Connecting to www.xxx.yyy.zzz...
UserName@www.xxx.yyy.zzz's password:
sftp> cd IN
sftp> lcd /usr/autoftp/xfr
sftp> put *
Uploading test.csv to /HOME/IN/test.csv
test.csv 100% 726KB 5.4KB/s 02:15
sftp> quit
DEBIAN:/usr/autoftp/scripts#

and the file transfers properly.

However, if I run an expect script that looks like this:

#!/usr/bin/expect
spawn sftp UserName@www.xxx.yyy.zzz
expect "password:"
sleep 2
send "password\r"
expect "sftp>"
send "cd IN\r"
expect "sftp>"
send "lcd /usr/autoftp/xfr\r"
expect "sftp>"
send "put *\r"
expect "sftp>"
send "exit\r"

I get the file transferring to about 60-70% then failing, with no error message. I tried running the sftp with the "-v" switch, but got no information about why the transfer failed. I looked in all the obvious places in /var/log and got nothing. This us utterly reproducible, but I've failed to find the reason...any clues?

And I just noticed the interactive work ends in "quit" while the script ends in "exit" but I don't *think* that will make a material difference, because the error is happening upstream of the difference.

(And yes, I know embedding passwords in a file is not clever, but humour me, I just want to get a script that runs so I can cron it....)

Thanks for any suggestions

Last edited by jimbo1954; 11-26-2008 at 10:06 AM.
 
Old 11-26-2008, 07:57 PM   #2
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,797

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by jimbo1954 View Post
Guys,
I have a Linux Server (Debian 2.6.18-6-686)from which I want to sftp files to an external (unknown other than some form of windows)server.

.
.
.

I get the file transferring to about 60-70% then failing, with no error message.

.
.
.
You mentioned that the problem is reproducible but have you measured how long it takes for the transfer to fail? I'm betting it's less time than it takes for your manual transfer to complete.

Expect scripts have a timeout (ten seconds by default, if memory serves) that I suspect you will need to increase so that there's sufficient time for your transfers to complete before expect gives up waiting for the response from sftp when the transfer finishes. If you are confident that the transfers won't (ever) fail, you can set the timeout to infinity by including the statement:
Code:
set timeout -1
near the top of your script or, even better, just before you actually begin the file get/put. Watch out, though, because your script could really hang is there's a connection problem between the two hosts. Better to set it to some reasonable value after running it a few times with a large value and getting the true elapsed time, then increasing it by some fudge factor to reduce the chance of false timeouts. I have some file transfers at work that used to have a timeout of 600 seconds (they're big files) but have actually had to be increased to 1800 seconds (the files have increased in size over time).

And... I don't think "exit" is a recognized sftp command. I've always used "quit".

Hope this helps...

--
Rick
 
1 members found this post helpful.
Old 11-27-2008, 03:07 AM   #3
jimbo1954
Member
 
Registered: Oct 2006
Location: High Wycombe, Bucks, UK.
Distribution: Debian and Fedora Core in equal measure
Posts: 264

Original Poster
Rep: Reputation: 33
Problem Solved!

Thanks Rick, that hit the nail right on the head...I've been using Linux and shell scripting for years, but never used expect before, hence the error, but as soon as I applied your suggested fix: Bingo, the xfer works correctly.

Many thanks for your swift help
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Check for Success of SFTP transfer using expect kasthana Programming 4 06-03-2008 10:55 AM
transfer file using expect and sftp tanveer Linux - General 7 05-16-2008 10:29 AM
fail running 3D OS on my computer, what to do?? agussuwarso Linux - Newbie 2 03-11-2008 01:35 AM
Samba transfers fail on large files from Windows to Debian mperkins Linux - Networking 11 08-09-2005 03:46 PM
GUI sFTP for gentoo 2004.3 running gnome/xorg gauntalus Linux - Software 1 01-14-2005 01:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration