Google
 
 
Home arrow Other Articles arrow Automating SFTP using expect

Main Menu
 Home
 Linux Articles
 FreeBSD Articles
 Apache Articles
 Perl Articles
 Other Articles
 Program Downloads
 Free Books
 News
 The Web Links
 Contact Us

Most Read
Automating SFTP using expect
FreeBSD PPTP VPN
Shorewall Router on Linux
Shorewall Stand Alone Firewall
SnortShorwall - Using Snort And Shorewall Together

Polls
Favorite Linux/BSD
Fedora
Mandrake
Debian
Slackware
Gentoo
Suse
FreeBSD
Other
  

Syndicate
Latest news direct to your desktop
RSS

Login Form
Username

Password

Remember me
Forgotten your password?
No account yet? Create one

Members Online
 Linux-BSD-Central Has a Total of 139 Members   Members (139) # Online
 We have 18 Guests Online. Guests 18
 We have 0 Users Online. Users 0

Online Users
No Users Online

Statistics
OS: Linux b
PHP: 5.2.5
MySQL: 5.0.45-community-log
Time: 16:38
Members: 139
Hits: 731664
News: 269
WebLinks: 15




Automating SFTP using expect   PDF  Print  E-mail 
Contributed by Chad Brandt  
Saturday, 19 June 2004

You may need to automate transferring of files and the only protocol you have available to you is SSH. You can accomplish this using expect and SFTP

Expect (http://expect.nist.gov/) is a tool for automating interactive programs. To use expect to automate file transfer with SFTP, we have to first create the expect script

#!/usr/local/bin/expect

spawn  sftp  -b cmdFile user@yourserver.com
expect "password:"
send "shhh!\n";
interact

This will spawn sftp in batch mode and pass in the password shhh! to the program. SFTP will than execute all the commads in cmdFile

cmdFile
lcd /home/ftp/test
cd /home/ftp/somedir
mput *.dat

lcd /home/recieving
cd /home/someotherdir
mget *.dat


Another alternative would be to use Perl to automate the SCP. You could do this with the following example

#!/usr/bin/perl -w

use Net::SFTP;
use strict;

my $host = "host.ssh.com";
my %args = (
    user => 'your_user_name,
    password => 'your_password',
    debug => 'true'
);

my $sftp = Net::SFTP->new($host, %args);
$sftp->get("/home/user/something.txt", "/home/user/hey.txt");
$sftp->put("bar", "baz");

Comments
Brillant!
Written by Guest on 2004-08-18 10:54:25
thx! 
:p
Nice ...BUT ???
Written by Guest on 2004-10-07 14:22:05
I have followed the examples here, but still cannot get the password to enter...tried expect as noted above and the full string returned to the script and neither works...any ideas ?? 
:grin
Written by Guest on 2004-10-08 07:41:30
did you include the new line character \n at the end of the password
sftp/expect exception conditions
Written by Guest on 2004-10-20 12:56:02
I have a working expect script for sftp and it works fine unless there is an unexpected response or error condition. I have not been able to determine how to handle the many exception conditions that may occur. Is there a good source for this type of information?
Super!
Written by Guest on 2004-11-28 14:43:28
:) it works fine!
I don't get password prompt
Written by Guest on 2005-04-15 20:50:39
When I run sftp with -b option it does not seem to allow interactive password entry at all so expect cannot help me. Is there a workaround for this to force it to prompt for the password when in batch mode?
Written by Guest on 2005-07-20 12:15:32
8)
unix shell script for sftp...
Written by Guest on 2005-08-26 02:20:56
Its working fine in linux...but when i tried to execute in unix..I am unable to find "send,spawn,expect" utility files... Is there any other alternative to suppress interactive password during the execution of script?...help me out in  
unix shell script...
Install expect on unix
Written by Guest on 2005-08-26 07:10:31
expect is not installed by default. Download the program and install it on the unix machine

Only registered users can write comments.
Please login or register.

Powered by AkoComment 1.0 beta 2!




 
Google Ads