脚本继续执行,然后在bin / expect中使用sftp进行下浮动

问题描述 投票:0回答:1

我有一个脚本,可从ssh服务器下载文件。它运行正常,可以开始下载,但是在下载完成之前会从下载继续进行。有没有办法等到下载完成?我已尝试等待,但只是暂停。

#!/usr/bin/expect

spawn sftp root@ip
expect "password"
send "<password>\r"

expect "sftp>"
send "lcd Desktop\r"
expect "sftp>"
send "cd Desktop\r"
expect "sftp>"
send "get -r File\r"
wait
close
wait
sftp expect
1个回答
0
投票

expect将使用$timeout设置放弃正在等待的内容,并将继续执行脚本。要一直等到模式匹配,请执行

set timeout -1

所以

expect "sftp>"
send "get -r File\r"
set timeout -1
expect "sftp>"
send "exit\r"     ;# exit gracefully
expect eof
© www.soinside.com 2019 - 2024. All rights reserved.