ssh2_scp_send() and ssh2_scp_recv() functions are not working in php. Why?

3.9k Views Asked by At

ssh2_scp_send() function is hanging in php. Here's the code:

$debug_line_feed = "\n";
$conn = ssh2_connect($sftp_server, 22);
$return = ssh2_auth_password($conn, $sftp_user_name, $sftp_user_pass);
if ($return===true) echo "successfull connection".$debug_line_feed;

echo "uploading file".$debug_line_feed;
$local_filename = $product_feed_file_with_path;
$remote_filename = 'product_feed.txt';
ssh2_scp_send($conn, $local_filename, $remote_filename);
echo "successful".$debug_line_feed;

When i run it, it outputs "successful connection", "uploading file" then hangs. Any idea how to fix this?

I have tried a download as well with ssh2_scp_recv, and it hangs as well, with the local file being created as a 0 byte file.

2

There are 2 best solutions below

2
On BEST ANSWER

My guess is that the server has a jail shell installed. At that point SCP wouldn't work but SFTP would.

0
On

recently,i use sftp to send file,linux to windows,ssh2_scp_send not work,i solve the problems use

$sftp = ssh2_sftp($conn);
 $contents = file_get_contents($localPath);
 $result = file_put_contents("ssh2.sftp://{$sftp}/{$remotePath}", $contents);

then works