【发布时间】:2013-09-05 18:03:00
【问题描述】:
数据供应商已请求一个公共 SSH 密钥以使用其 SFTP 服务器。他们为我们提供了:
- 用户名
- 密码
- 主机名
- 端口
我正在尝试使用私钥和用户名/密码在 php 中使用流包装器 ssh2.sftp//。我的代码如下:
$options = array(
'ssh2' => array(
'privkey_file' => '/path/to/priv_key',
),
);
$context = stream_context_create($options);
fopen('ssh2.sftp://<username>:<password>@<host>:<port>', 'rb', false, $context);
结果:
Warning: fopen(ssh2.sftp://...@<ip>...): failed to open stream: operation failed in ...
我可以使用 linux 的 sftp 命令进行连接,因此我知道连接正常,并且凭据工作正常。
sftp -oPort=<port> -i /path/to/priv_key -v <username>@<host>
结果:
Authenticated with partial success.
password: <password-entered>
debug1: Authentication succeeded (password).
debug1: channel 0: new [client-session]
debug1: Sending subsystem: sftp
sftp>
有人有什么想法吗?
我对使用ssh2 函数的想法持开放态度,但我强烈希望使用file system 和stream 函数。
【问题讨论】:
-
密码 + 密钥对我使用 cURL 效果很好。其他人发布了cURL stream wrapper。
-
我认为supplied resource is not a valid SSH2 SFTP resource 是这个问题的答案。