【问题标题】:Unable to mput all the files through sftp in the remote server using expect无法使用期望在远程服务器中通过 sftp 输入所有文件
【发布时间】:2018-11-15 07:09:48
【问题描述】:

我正在尝试mput 目录中存在的所有文件:/Test/XML/expect 实用程序的帮助下进入远程 sftp 服务器。

我在目录中有大约 320 个文件:/Test/XML/。

每个文件的大小约为 0.1 MB。

没有观察到错误。

这是我的代码:

cd /Test/XML/

/usr/bin/expect <<EOF
spawn /usr/bin/sftp ${user_name}@${HOSTNAME}
expect "password:"
send "${passwd}\r"
expect "sftp>"
send "cd /test\r"
expect "sftp>"
send "mkdir XML\r"
expect "sftp>"
send "cd /test/XML\r"
expect "sftp>"
send "mput *\r"
expect "sftp>"
send "bye\r"
EOF 

但这里的问题是,mput * 只传输 4 个文件,而不是传输所有 320 个文件。 不知道为什么它不能传输远程服务器中的所有320个文件。

欢迎任何帮助。

【问题讨论】:

  • 在脚本存在之前你有没有得到任何错误??我的意思是连接中止或与代理有关的东西?
  • 您检查是否可以关闭交互式提示(PROMPT 命令)?
  • 您也可以尝试递归,将mput 替换为put -r *,这样它会随文件夹一起传输文件(如果有)。
  • @ThiruShetty:我在调试模式下运行脚本。没有观察到错误。我只需要传输文件。
  • set timeoutexpect 的一部分,而不是sftp 的一部分,所以您不要将send 发送到FTP 服务器,您只需将其作为期望脚本的第一行。

标签: linux bash sftp expect


【解决方案1】:

感谢@ThiruShetty 提示在expect 实用程序中使用set timeout -1

实际上,我有很多文件(~320-350)要传输(sftp)到远程服务器。 在使用expect 实用程序正常执行sftp 时,它只能传输几个文件,而不是我想要的所有文件。

expect里面插入set timeout -1后,就解决了超时问题。

这是最终代码:

cd /Test/XML/

/usr/bin/expect <<EOF
set timeout -1
spawn /usr/bin/sftp ${user_name}@${HOSTNAME}
expect "password:"
send "${passwd}\r"
expect "sftp>"
send "cd /test\r"
expect "sftp>"
send "mkdir XML\r"
expect "sftp>"
send "cd /test/XML\r"
expect "sftp>"
send "mput *\r"
expect "sftp>"
send "bye\r"
EOF

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-07
    • 1970-01-01
    • 2021-12-27
    • 1970-01-01
    • 1970-01-01
    • 2019-01-15
    • 2016-06-23
    • 1970-01-01
    相关资源
    最近更新 更多