2

我正在尝试连接到 SFTP 服务器并通过 php 上传文件。

我已经安装了 php lib (php_ssh2),但此时它失败了:

<?php
$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');


$sftp = ssh2_sftp($connection);

?>

最后一行返回 false,日志中显示以下警告:

 Warning: ssh2_sftp(): Unable to startup SFTP subsystem: Unable to request SFTP subsystem 

我不知道这是否与我尝试使用 sftp 命令通过命令行连接到同一服务器时遇到的错误有关:

sftp error subsystem request failed on channel 0

我已经尝试按照一些人的建议用 internal-sftp 替换我的 sshd_config 的 Subsystem sftp /usr/lib/openssh/sftp-server 行,但它没有用(我认为这是为了连接到本地sftp 服务器)

我已经尝试重新安装 openssh-client 和 openssh-server (尽管我认为最后一个不应该是必需的,因为服务器是外部主机)。

我尝试使用 Filezilla 登录 SFTP,一切正常。

另外,我尝试过 phpseclib,但即使使用正确的凭据,它也会在登录时出错。

因此,我无法通过 PHP 或命令行将文件上传到 sftp 服务器。

你有我在这里想念的东西的队列吗?

编辑:

phpseclib日志太长,我贴在这里(请告诉我如何附加它,以防它不允许放置这种链接): http: //pastebin.com/Kkw027nR

这是 FileZilla 日志http://pastebin.com/6u90646Q,我注意到问题可能与这两行有关,但我不确定:

2013-05-07 08:16:15 2704 3 Traza: Opened channel for session
2013-05-07 08:16:15 2704 3 Traza: Primary command failed; attempting fallback

谢谢你,哈维尔

4

1 回答 1

2

It seems that there were a problem on the server's config that was causing the connections attempts to fail. Anyway, both FileZilla and Putty (psftp) were able to connect successfully by some kind of fallback in case of failure.

I can't explain the details, but after sharing the logs with phpseclib's creator, he has been able to implement this fallback on his lib as well, so now I'm able to successfully connect to the sftp server using the latest version of phpseclib (https://github.com/phpseclib/phpseclib).

For more details about the problem, check this out: http://www.frostjedi.com/phpbb3/viewtopic.php?f=46&t=168285

Special thanks to TerraFrost for his patience and help to get the solution.

于 2013-05-15T12:29:54.547 回答