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

点点圈 提交于 2019-12-01 02:23:43

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!