3

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.

Moses Schwartz
  • 2,857
  • 1
  • 20
  • 32
danjfoley
  • 778
  • 1
  • 8
  • 20

2 Answers2

3

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

prekblub
  • 46
  • 1
  • 1
    This is exactly it. I had to use file operation functions with sftp. Should I post my code as the solution? – danjfoley Sep 01 '15 at 02:50
  • @danjfoley Hi, I am having this exact same problem. This is a really old thread, but could you by any chance tell me exactly how to fix it? – Tina Nov 10 '19 at 07:36
2

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

dannyqun
  • 21
  • 3