Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用用户名、密码和;钥匙对_Php_Ssh_Stream_Sftp - Fatal编程技术网

Php 使用用户名、密码和;钥匙对

Php 使用用户名、密码和;钥匙对,php,ssh,stream,sftp,Php,Ssh,Stream,Sftp,数据供应商已请求使用其SFTP服务器的公共SSH密钥。他们向我们提供了: 用户名 密码 主机名 港口 我试图使用私钥和用户名/密码在php中使用流包装器ssh2.sftp/。我的代码如下: $options = array( 'ssh2' => array( 'privkey_file' => '/path/to/priv_key', ), ); $context = stream_context_create($options); fopen('

数据供应商已请求使用其SFTP服务器的公共SSH密钥。他们向我们提供了:

  • 用户名
  • 密码
  • 主机名
  • 港口
我试图使用私钥和用户名/密码在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);
$options=array(
“ssh2”=>阵列(
'privkey_file'=>'/path/to/priv_key',
),
);
$context=stream\u context\u create($options);
fopen('ssh2.sftp://:@:','rb',false,$context);
结果:

Warning: fopen(ssh2.sftp://...@<ip>...): failed to open stream: operation failed in ...
Authenticated with partial success.
password: <password-entered>
debug1: Authentication succeeded (password).
debug1: channel 0: new [client-session]
debug1: Sending subsystem: sftp
sftp>
警告:fopen(ssh2。sftp://...@…):无法打开流:操作在。。。
我可以使用linux的sftp命令进行连接,因此我知道连接工作正常,凭证工作正常

sftp -oPort=<port> -i /path/to/priv_key -v <username>@<host>
sftp-oPort=-i/path/to/priv_key-v@
结果:

Warning: fopen(ssh2.sftp://...@<ip>...): failed to open stream: operation failed in ...
Authenticated with partial success.
password: <password-entered>
debug1: Authentication succeeded (password).
debug1: channel 0: new [client-session]
debug1: Sending subsystem: sftp
sftp>
验证部分成功。
密码:
debug1:身份验证成功(密码)。
调试1:通道0:新建[客户端会话]
debug1:发送子系统:sftp
sftp>
有人有什么想法吗


我对使用函数的想法持开放态度,但我强烈希望使用and函数。

老实说,我认为您最好使用。与libssh2相比,用它诊断问题更容易

此外,如果要使用文件系统和流函数,phpseclib还支持以下功能:


使用cURL时,密码+密钥对我来说效果很好。其他人发布了一个。我想这是这个问题的答案。