使用PHP系统和cURL时的权限问题?

发布于 2024-12-09 13:46:03 字数 904 浏览 0 评论 0原文

我正在尝试创建一个 php 脚本,将文件放在远程服务器上。
以下行将在 CLI 中运行:

curl -u username:pass -T myfile.jpg sftp://my.domain.com/dir/

但是,如果我将其引入 PHP 并尝试通过“系统”运行它,例如:

<? system('curl -u username:pass -T myfile.jpg sftp://my.domain.com/dir/'); ?>

我收到一个错误:

curl: (7) Failed to connect to xxx.xxx.xx.xx: Permission denied

另外,让事情变得复杂的是,这是从 RHEL 到 Windows Server。有人有建议或解决办法吗?

下面是 PHP cURL 库的结果。

* About to connect() to my.domain.com port 22 (#0)
*   Trying xxx.xxx.xx.xx... * connected
* Connected to my.domain.com (xxx.xxx.xx.xx) port 22 (#0)
* SSH authentication methods available: publickey,password
* Initialized password authentication
* Authentication complete
* Upload failed: Permission denied (3/-31)
* Connection #0 to host my.domain.com left intact
* Closing connection #0

I'm trying to create a php script that will put a file on a remote server.
The following line will work from the CLI:

curl -u username:pass -T myfile.jpg sftp://my.domain.com/dir/

However, if I take this into PHP and try to run it through 'system' like:

<? system('curl -u username:pass -T myfile.jpg sftp://my.domain.com/dir/'); ?>

I get an error:

curl: (7) Failed to connect to xxx.xxx.xx.xx: Permission denied

Also, to complicate things, this is going from a RHEL to a Windows Server. Anyone have a suggestion or a fix?

Below is the result from the PHP cURL library.

* About to connect() to my.domain.com port 22 (#0)
*   Trying xxx.xxx.xx.xx... * connected
* Connected to my.domain.com (xxx.xxx.xx.xx) port 22 (#0)
* SSH authentication methods available: publickey,password
* Initialized password authentication
* Authentication complete
* Upload failed: Permission denied (3/-31)
* Connection #0 to host my.domain.com left intact
* Closing connection #0

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

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

发布评论

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

评论(2

素年丶 2024-12-16 13:46:03

PHP 有它自己的 cURL 库,您可能应该使用它。 php cURL

PHP has it's own cURL library that you should probably use. php cURL

相思故 2024-12-16 13:46:03

您的问题是 system() 不允许 curl 要求您输入密码。

考虑其他身份验证方法。

Your problem is that system() doesn't allow curl to ask you for a password.

Consider other authentication methods.

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