使用PHP系统和cURL时的权限问题?
我正在尝试创建一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PHP 有它自己的 cURL 库,您可能应该使用它。 php cURL
PHP has it's own cURL library that you should probably use. php cURL
您的问题是
system()
不允许curl
要求您输入密码。考虑其他身份验证方法。
Your problem is that
system()
doesn't allowcurl
to ask you for a password.Consider other authentication methods.