Expect Script ile SFTP

Unix veya Linux sistemlerde Expect Script ile SFTP programını parametrik çağırma


burhansftp.exp


# !/usr/local/bin/expect -f
set login [lrange $argv 0 0]
set passw [lrange $argv 1 1]
set localfile [lrange $argv 2 2]
set remotefile [lrange $argv 3 3]
set timeout -1
spawn sftp $login
expect “assword:”
send “$passw\r”
expect “sftp>”
send “lcd /usr/sap/Bankagonderilecek/ \r”
expect “sftp> “
send “put $localfile $remotefile \r”
expect “sftp> “
send “bye \r”


burhansftp.exp kullaniciadi@ip password local_file remote_file


burhansftpilk.exp


# !/usr/local/bin/expect -f
set login [lrange $argv 0 0]
set passw [lrange $argv 1 1]
set timeout -1
spawn sftp $login
expect “Are you sure you want to continue connecting (yes/no)?”
send “yes\r”
expect “assword:”
send “$passw\r”
expect “sftp> “
send “bye \r”


burhansftpilk.exp


burhansftpcmd.exp de su sekilde:


# !/usr/local/bin/expect -f
set login [lrange $argv 0 0]
set passw [lrange $argv 1 1]
set command [lrange $argv 2 4]
set timeout -1
spawn sftp $login
expect “assword:”
send “$passw\r”
expect “sftp>”
send “$command \r”
expect “sftp> “
send “bye \r”


burhansftpcmd.exp user@IP sifre komut (mesela “rm klasor/*.txt”)


burhansftpmget.exp


# !/usr/local/bin/expect -f
set login [lrange $argv 0 0]
set passw [lrange $argv 1 1]
set remotepath [lrange $argv 2 2]
set localpath [lrange $argv 3 3]
set timeout -1
spawn sftp $login
expect “assword:”
send “$passw\r”
expect “sftp> “
send “get $remotepath $localpath/. \r”
expect “sftp> “
send “bye \r”


sapsftpmget.exp $login(user@IP) $password $remotepath $localpath


VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)