Files sent using ssh2_scp_send () are incomplete on the remote server

I am transferring files from PHP and SSH2 to a remote server.

I use this:

$connection = ssh2_connect('shell.example.com', 22); ssh2_auth_password($connection, 'username', 'password'); ssh2_scp_send($connection, '/local/filename', '/remote/filename', 0644); 

But sometimes the file on the remote server is incomplete. I have an assumption that SSH2 is not transmitting EOF or anything else.

Do you have any ideas or solutions?

+6
source share
1 answer

The problem is that you are not closing the SSH session. Thus, internal buffers are not flushed, and files are not completely written to disk.

Here is a workaround - just close the session with:

 ssh2_exec($connection, 'exit'); 

This will reset all buffers, and your files should be fully migrated.

Hope this helps.

+17
source

Source: https://habr.com/ru/post/899399/


All Articles