Page 1 of 1

SSH SCP functions not working with a certain server

Posted: Fri Mar 21, 2008 12:53 am
by chadjohnson
I can successfully transfer files to and from my server using the following code:

Code: Select all

 
$connection = ssh2_connect('hostname', 3222);
ssh2_auth_password($connection, 'username', 'password');
 
$sftp = ssh2_sftp($connection);
 
ssh2_scp_send($connection, '/local/directory/bug.gif', '/remote/directory/bug.gif', 0644);
ssh2_scp_recv($connection, '/remote/directory/bug.gif', '/local/directory/bug2.gif');
 
but when I try to do the same with a second server (have not tried a third) I get

Code: Select all

 
Warning: ssh2_scp_send(): Failure creating remote file in /media/data/srv/www/test/sftp/prototype.php on line 8
 
Warning: ssh2_scp_recv(): Unable to receive remote file in /media/data/srv/www/test/sftp/prototype.php on line 9
 
The second server uses port 3222. I can in fact scp into this second server and transfer files via the command line as well as FileZilla and gFTP just fine. I do in fact have read/write permission on the target directory.

What's going on? Please help if possible--it's very urgent.

Re: SSH SCP functions not working with a certain server

Posted: Fri Mar 21, 2008 2:53 am
by Chris Corbyn
I'm not familiar with those functions, but speaking generally from an SSH point of view, perhaps the other server uses a type of key or authentication which those functions do not support? For example, maybe those function rely on password logins being enabled in sshd_config? Do you know anything about the configurations of the two servers?

EDIT | I assume your running this code *from* the same server? The other possibility is that your web host have certain ports firewalled off.

Re: SSH SCP functions not working with a certain server

Posted: Fri Mar 21, 2008 11:15 am
by chadjohnson
Chris Corbyn wrote:I'm not familiar with those functions, but speaking generally from an SSH point of view, perhaps the other server uses a type of key or authentication which those functions do not support? For example, maybe those function rely on password logins being enabled in sshd_config? Do you know anything about the configurations of the two servers?
Could password logins sshd_config still be disabled, considering I can log in via sftp on the command line? I noticed from the get go that I was unable to log into the second server via 'ssh user@host -p 3222'--but like I said, I can log in via sftp.
Chris Corbyn wrote: EDIT | I assume your running this code *from* the same server? The other possibility is that your web host have certain ports firewalled off.
Nope, the code is being run from a different server--my personal server--and I have no firewall such outgoing firewall restrictions in place. The server I am trying to connect to has port 3222 open.


One additional interesting thing I forgot to add is that I CAN upload files to the server like this:

Code: Select all

 
$fp = fopen("ssh2.sftp://$sftp/directory/bug.gif", "wb");
fwrite($fp, $buffer, strlen($buffer));
fclose($fp);
 
I can also download files (although, when I try, the program gets stuck in an infinite loop: while (!feof($fp)) { ... } -- apparently it cannot tell whether eof has been reached on the stream).

Re: SSH SCP functions not working with a certain server

Posted: Fri Mar 21, 2008 8:14 pm
by Chris Corbyn
Could password logins sshd_config still be disabled, considering I can log in via sftp on the command line? I noticed from the get go that I was unable to log into the second server via 'ssh user@host -p 3222'--but like I said, I can log in via sftp.
Sounds like you don't have a shell (/bin/sh, /bin/bash etc) in /etc/passwd on that second server. It's probably set to /bin/false to prevent you from physically gaining shell access.

The SCP stuff needs shell access in order to execute the remote command.

Re: SSH SCP functions not working with a certain server

Posted: Wed Mar 26, 2008 3:18 pm
by chadjohnson
Well, turns out that file_get_contents() allows me to download the file.

So to upload, I use fopen("ssh2.sftp://$sftp/path/to/image.gif", 'w');, and do download I use file_get_contents("ssh2.sftp://$sftp/path/to/image.gif");

Thanks for the help everyone :)