文件未下载且超时 PHP 并使用 Expect

File not downloaded and being timeout with PHP and using Expect

我有两个文件,script.php(到运行期望文件),script.exp(期望文件获取/下载文件),但我遇到了一些问题script.exp 我要下载的文件没有被下载,我很确定代码几乎是正确的,现在我卡住了,请帮忙,这是我的代码:

script.php

function downloadreal(){
exec("expect /home/script.exp");}

script.exp

#!/usr/bin/expect
set timeout 10
set pass "password"
    spawn sftp -oPort=2123 sftp@ftp.mynet.com
    expect "*you sure you want to continue*"
    send "yes \r"
    expect {
        timeout {puts "Time out!"; exit}
        "*password:"
    }
    send "$pass\n"
    expect "*sftp>"
    send "ls -l \r"
    expect "*sftp>"
    send "get *.csv \r"
    expect "*sftp>"
    send "bye \r"
    expect ""
    expect "*\r"
    expect "\r"

谢谢

答案是,在script.exp上添加这段代码:

expect {
        "(yes/no)" { send "yes\r";exp_continue}
        "password"
    }

所以,最终的代码将是这样的:

#!/usr/bin/expect
set timeout 10
set pass "password"
    spawn sftp -oPort=2123 sftp@ftp.mynet.com
    expect {
        "(yes/no)" { send "yes\r";exp_continue}
        "password"
    }
    send "$pass\n"
    expect "*sftp>"
    send "ls -l \r"
    expect "*sftp>"
    send "get *.csv \r"
    expect "*sftp>"
    send "bye \r"
    expect ""
    expect "*\r"
    expect "\r"

谢谢,我已经解决了