SCP通过php脚本将文件从本地主机传输到sftp服务器

发布于 2024-09-24 06:08:42 字数 413 浏览 2 评论 0原文

您好,尝试使用 scp 将文件发送到另一台服务器。无法使用 sftp,因为它没有安装在我的服务器上,所以我得到了一个未找到 ssh2_connect 的函数。

所以我唯一的选择是 scp。 现在问题来了,我无法在 php scp 脚本中包含我的密码。

即:

scp filename username:passwor@server:filename

它给了我服务器用户名不存在的错误 如果我在没有密码的情况下使用它,

scp filename username@server:filename

它会提示我输入密码

PS:我首先在本地主机上的命令行中测试脚本以获取错误消息。

有什么建议吗?

TA

Hi Trying to send a file to another server using scp.. cannot use sftp as it is not installed on my server so i am getting a function not found for ssh2_connect.

So my only option as i can see it is scp.
Now the problem come with i cannot include my password in the php scp script.

ie:

scp filename username:passwor@server:filename

It gives me the error that the server username doesn't exist
If i use it without the password

scp filename username@server:filename

it prompts me for password

PS: I am testing the script in a command line on the localhost first as to get the error messages.

Any advice?

TA

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

獨角戲 2024-10-01 06:08:42

如果您无法使用 SFTP 二进制文件,您可以使用 phpseclib - 纯 PHP SFTP 实现:

http://phpseclib。 sourceforge.net/

If you can't use the SFTP binaries you could use phpseclib - a pure-PHP SFTP implementation:

http://phpseclib.sourceforge.net/

Saygoodbye 2024-10-01 06:08:42

Kevin,如果您的服务器上没有安装 PHP SSH2 扩展,那么您最好的选择是在您有权访问的其他服务器上设置公钥/私钥身份验证。然后,您可以将私钥保留在 PHP 服务器上,并在 scp 命令上传递 -i,如下所示:

scp -i /var/www/htdocs/myphpproject/rsakey filename username@server:filename

Kevin, if you don't have the PHP SSH2 extension installed on your server then your best bet is to setup public/private key authentication on your other server if you have access. Then you can keep the private key on your PHP server, and pass -i on your scp command, something like this:

scp -i /var/www/htdocs/myphpproject/rsakey filename username@server:filename

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文