Friday, April 17, 2009

Automatic SFTP to server to get files - Using Expect

#!/usr/bin/expect
set DAY [exec date +%Y-%m-%d]
set timeout -1
spawn /usr/bin/sftp retheesh@3.212.44.46
#spawn sftp retheesh@3.212.44.46
expect "password:";
send "1\r";expect "
sftp>"send "lcd /home/retheesh/sftp/\r"
expect "sftp>"send "cd /home/retheesh/destination/\r"
expect "sftp>"send "mget *$DAY*.csv\r"
expect "sftp>"send "bye\r"
interact

ftp using Shell Script
#!/usr/bin/sh
#DAY=`date +%Y%m%d`
ftp -v -n "3.xxx.xxx.xxx" << cmd
user "anonymous" "test@test.com"
cd retheesh
lcd /root/Ironport/
bin
hash
get filename
quit

1 comment:

Anonymous said...

Can you please explain me more