Why would SSH commands through Putty work differently to those via PHP's phpseclib?

前端 未结 1 995
北恋
北恋 2021-01-07 15:15

I\'m writing a script to automate deployment from my windows development PC to a shared hosting server.

I am getting different results depending on whether I execute

相关标签:
1条回答
  • 2021-01-07 16:07

    From the documentation:

    Successive calls to exec()

    If done on an interactive shell, the output you'd receive for the first pwd would (depending on how your system is setup) be different than the output of the second pwd. The above code snippet, however, will yield two identical lines.

    The reason for this is that any "state changes" you make to the one-time shell are gone once the exec() has been ran and the channel has been deleted.

    I see two options. Option 1:

    Try the interactive shell examples with the read() and write() functions, which look pretty ugly to me.

    Option 2:

    Write your script as a shell script on the server and call the script with a single $ssh->exec() call.

    0 讨论(0)
提交回复
热议问题