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

时间:2018-09-26 08:40:37

标签: php 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"

谢谢

1 个答案:

答案 0 :(得分:0)

答案是,将此代码添加到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"

谢谢,我已经解决了