Javier C. H.
Javier C. H.

Reputation: 2123

Uploading a file to a SFTP server

I'm trying to connect to a SFTP server and upload a file through php.

I've installed php lib (php_ssh2) but it's failing at this point:

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


$sftp = ssh2_sftp($connection);

?>

The last line is returning false and the following warning is shown on the log:

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

I don't know if it has something to do with the error that I'm getting when I try to connect to the same server through commandline with sftp command:

sftp error subsystem request failed on channel 0

I've tried replacing the line Subsystem sftp /usr/lib/openssh/sftp-server of my sshd_config by internal-sftp as some people suggested, but it didn't work (I expected that as I think it's for connecting to a local sftp server)

I've tried reinstalling openssh-client and openssh-server (although I think the last one shouldn't be required, as the server is an external host).

I've tried to login to the SFTP with Filezilla and everything works smoothly.

Also, I've tried phpseclib, but it's giving an error on the login, even with the proper credentials.

So, I'm unable to upload a file to the sftp server neither by PHP nor by commandline.

Do you have a queue of what I'm missing here?

EDIT:

The phpseclib log is too long, I've pasted it here (please tell me how to attach it in case it's not allowed to put this kind of links): http://pastebin.com/Kkw027nR

This is the FileZilla log http://pastebin.com/6u90646Q, I've noticed that maybe the problem is related with this two lines but I'm not sure:

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

Thank you, Javier

Upvotes: 2

Views: 4155

Answers (1)

Javier C. H.
Javier C. H.

Reputation: 2123

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.

Upvotes: 2

Related Questions