这是我的剧本
#!/bin/ksh
RemoteFile=`grep "${File}" ${TempLog}` --> the value of the variable is Site Information_2013-07-04-00-01-26.CSV
/usr/bin/expect << EOF
spawn sftp user@server
expect "password:"
send "123fakepassword\n"
expect "sftp>"
send "cd /home/user/pickup_dir\n"
expect "sftp>"
send "lcd /home/user/Scripts/mart/wmt/RAMDISK0\n"
expect "sftp>"
send "get $RemoteFile\n" ---> I'm trying to pass it here so I can download the file.
expect "sftp>"
send "exit\r"
EOF
但没有运气!,我如何传递带双引号的文件名,以便它将执行为(获取“Site Information_2013-07-04-00-01-26.CSV \ n”)我将它放入变量导致日期文件名更改。或者我做错了吗?我知道硬编码密码不好,但我们不能使用ssh-key来设置无密码的sftp。谢谢!
答案 0 :(得分:0)
你只需要发一些报价。选择其中一个
send "get '$RemoteFile'\n"
send "get \"$RemoteFile\"\n"
答案 1 :(得分:0)
#!/bin/bash
while true
do
/usr/bin/expect <<EOF
set timeout 300
spawn sftp $remoteUser@$remoteIp
expect "yes/no" {
send "yes\r"
expect "*?assword" { send "$remotePass\r" }
} "*?assword" { send "$remotePass\r" }
expect "sftp> " { send "cd $RemoteFolderPath\r" }
expect "sftp> " { send "mget $remoteFileName\r" }
expect "sftp> " { send "quit\r" }
interact
EOF
done
exit