简体   繁体   English

sftp 使用 expect 自动传输文件不起作用

[英]sftp using expect to automate file transfer not working

I want automate below command so as to pass the password and proceed with file transfer.我想自动执行以下命令,以便传递密码并继续进行文件传输。

#This command works well but it will require password
echo "put This_file_from_server_a.csv /TO/THIS/SERVER_B/PATH" | sftp remote@10.11.12.13

i have tried to use expect , so as to automate/ send password automatically, but it is not working ie我曾尝试使用expect ,以便自动/自动发送密码,但它不起作用,即

expect -c 'spawn "put This_file_from_server_a.csv /TO/THIS/SERVER_B/PATH" | sftp remote@10.11.12.13; expect "assword:"; send "THE_PASSWORD\r"; interact'

I get error我得到错误

send: spawn id exp4 not open while executing "send "THE_PASSWORD\\r""发送:执行“发送“THE_PASSWORD\\r””时,生成 ID exp4 未打开

What could be the issue?可能是什么问题? without considering alternatives: such as sshpass , lftp , private keys ...不考虑替代方案:例如sshpasslftpprivate keys ...

Consider creating private keys on both servers that you are trying to do the transaction then try doing the same, it should work考虑在您尝试进行交易的两台服务器上创建私钥,然后尝试做同样的事情,它应该可以工作

in case it does not use expect as below.如果它不使用expect如下。

expect  <<'END_EXPECT'
set timeout -1
spawn sftp remote@10.11.12.13
expect "assword:"
send "THE_PASSWORD\r"
expect "sftp>"
send "put This_file_from_server_a.csv /TO/THIS/SERVER_B/PATH\r"
expect "sftp>"
send "quit\r"
expect eof
END_EXPECT

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM