简体   繁体   中英

Files sent with ssh2_scp_send() are incomplete on remote server

I transfer files with PHP and SSH2 to an 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 the assumption that SSH2 doesn't transfer the EOF or anything else.

Do you have any ideas or solutions?

The problem is that you don't close the SSH session. So the internal buffers aren't flushed and the files aren't written to disk fully.

Here is a workaround - just close the session with:

ssh2_exec($connection, 'exit');

This will cause all buffers to be flushed and your files should be transfered completely.

Hope, that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM