LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-31-2013, 10:41 AM   #1
manjuhp
LQ Newbie
 
Registered: Dec 2013
Posts: 3

Rep: Reputation: Disabled
Issues with expect sftp


Hi ,

This is my first question on the forum. Apologies if i have not posed question in the right category.

I have this sftp script using except to download files. The download stalls after downloading few files and exits. The number of files are around 6 and each file is not bigger than 150 MB. However when i manually download the file i do not face this issue.

Could someone tell if you notice any issue with the below script?

The timeout parameters at our end and client end are 30 minutes. I do not think the timeout as an issue. There are no threshold settings on datasize or number of files.

/usr/bin/expect <<EOF
set timeout 1200
catch {set prompt $env(EXPECT_PROMPT)}
spawn sftp -oPort=5408 xxxx@nn.nn.nn.nn
expect "password: "
send "XXXXXXX\r"
expect "sftp>"
send "ls -l *20131231* \r"
expect "sftp> "
send "get *20131231* \r"
expect "sftp> "
send "quit\r"
EOF

Thank you in advance
 
Old 01-01-2014, 11:48 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,553

Rep: Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946
Quote:
Originally Posted by manjuhp View Post
Hi ,
This is my first question on the forum. Apologies if i have not posed question in the right category.

I have this sftp script using except to download files. The download stalls after downloading few files and exits. The number of files are around 6 and each file is not bigger than 150 MB. However when i manually download the file i do not face this issue.

Could someone tell if you notice any issue with the below script?

The timeout parameters at our end and client end are 30 minutes. I do not think the timeout as an issue. There are no threshold settings on datasize or number of files.

/usr/bin/expect <<EOF
set timeout 1200
catch {set prompt $env(EXPECT_PROMPT)}
spawn sftp -oPort=5408 xxxx@nn.nn.nn.nn
expect "password: "
send "XXXXXXX\r"
expect "sftp>"
send "ls -l *20131231* \r"
expect "sftp> "
send "get *20131231* \r"
expect "sftp> "
send "quit\r"
EOF

Thank you in advance
I see no problems with the script itself, but since you're using SFTP, why are you bothering with expect? The whole purpose of SFTP is to be SECURE...putting names/passwords into a script file that anyone can read negates that security. Read the man page on the sftp command...pay particular attention to the "-b" (batch) flag, which may help you.

That said, you really don't need to be doing an "ls -l" in a script file, since it's pointless, when you're doing a 'get' later on SPECIFIC files. Why not use "mget *20131231*", to get MULTIPLE files with one statement? And since you can pass the host/user/password on the command line when you initiate the SFTP connection (again, see the man page), you're really going the long way around.
Code:
sftp -b <files to get> user@host
 
1 members found this post helpful.
Old 01-02-2014, 09:48 AM   #3
manjuhp
LQ Newbie
 
Registered: Dec 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
TB0ne thanks for the reply.
I believe there is no way to specify password using -b option. -b works fine for passwordless sftp accounts but not sure how to specify password when using -b option. I googled it and did not find any. Let me know if you are successful in using sftp -b with password.

thanks
 
Old 01-02-2014, 10:50 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,553

Rep: Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946
Quote:
Originally Posted by manjuhp View Post
TB0ne thanks for the reply.
I believe there is no way to specify password using -b option. -b works fine for passwordless sftp accounts but not sure how to specify password when using -b option. I googled it and did not find any. Let me know if you are successful in using sftp -b with password.
You can specify it when prompted for it. Again, putting a password into a script file is a BAD IDEA....and totally negates ANY security that using a secure protocol gives you.

You can do a simple ssh keyswap, and not NEED to put a password in at all...not only is it simpler to script for, but MUCH more secure.
 
Old 01-02-2014, 02:09 PM   #5
manjuhp
LQ Newbie
 
Registered: Dec 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
TB0ne, I agree what you say. The client is in favour of password usage,We did ask them about key validation but did not agree.The job runs from cron so manual entering password is ruled out. I might have found the problem for downloading stalling. something to do with one of the proxy on the loadbalancer.Will update soon

Thank you once again
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[root@fugo trace]# sh expect.sh expect.sh: line 9: expect: command not found sivaloga Linux - Kernel 1 08-22-2013 04:29 AM
set variable in expect to copy file through sftp hbchok Linux - Newbie 10 11-03-2012 04:23 AM
Running sftp under Expect and transfers fail jimbo1954 Linux - Software 2 11-27-2008 03:07 AM
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

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:37 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