scp stuck when trying to copy files from Linux to windows

12,134

Solution 1

This could be a sign of network issues - ping doesn't catch all issues. The most likely culprit is a firewall or NAT device that is dropping the connection.

Adding -v for verbose output to scp will give you more detail as to what it's doing, and may give a better clue as to what is going on. If you want to post the output of a failed transfer with the -v option, I may be able to give a more exact answer.

Connection reset by peer means exactly that - the destination server reset/closed the connection. NAT devices will do this if there hasn't been any data sent for awhile, or if they are not working correctly.

Some ISPs will do this as a form of traffic shaping to limit peer to peer traffic - unfortunately some apply it to SSH connections as well. This likely won't be an issue on business connections, but if either end has a residential internet connection, it may apply.

The SSH server on windows could also be flaky. You don't specify which one you use, but not all of them work reliably.

In one real life example of weirdness, I had a friend who had similar issues - it turned out to be a bug in his cable modem's firmware that corrupted one out of every couple million packets. Rare enough that small transfers worked perfectly, but large ones would die every time.

Or it could just be normal internet issues. The internet is not 100% reliable, and never will be. Sometimes connections fail, sometimes packets get lost along the way. Sometimes the tiny men inside the ethernet cable go on strike and don't feel like carrying your packets. So you need a tool that can handle that, and keep retrying until it succeeds.

rsync would be a better choice here, simply because it allows resuming. This blog post explains how to setup rsync with resuming in place of scp. If necessary, you could write a simple shell script to check the exit code of rsync and keep retrying if it fails. This other blog post has an example of such a script.

Solution 2

What the others good alternative for scp ? , (consider that I need 100% of stability)

Consider flipping it and using WinSCP from the Windows machine to connect and grab the files on the Linux server.

Share:
12,134

Related videos on Youtube

Eytan
Author by

Eytan

Updated on September 18, 2022

Comments

  • Eytan
    Eytan over 1 year

    I use the following scp syntax in order to transfer allot of files from Linux red-hat 5 to windows machine ( under Temp directory ),

    Remarks:

    • SSH server already installed on windows machine
    • I use this line in my shell scripts

       sshpass -p '$password'  /usr/bin/scp -o StrictHostKeyChecking=no  $FILE [email protected]:'D:/Temp'
      

    on most cases files transferred successfully

    but sometimes scp stuck during file transferring ? , in spite connectivity is ok like ping etc

    and I get the following error from scp ( after a long time )

       ssh_exchange_identification: read: Connection reset by peer
    
    1. why scp isn’t stable and stuck ? , and what the solution for this problem?
    2. What the others good alternative for scp ? , (consider that I need 100% of stability)
    • 0xFE
      0xFE almost 11 years
      A network tracing tool like Microsoft Network Monitor or Wireshark might be able to give you more details on why the connection is being reset.
    • Gagravarr
      Gagravarr almost 11 years
      Rsync over SSH would seem like being a much better fit for you than straight SCP, is there a reason why you're not using rsync?
    • Drav Sloan
      Drav Sloan almost 11 years
      I would imagine you are coming across a named pipe (or FIFO) because you are copying from the temp directory. I would go with gagravarr and say in this case you may want to look at rsync as a viable alternative. Examples in stackoverflow.com/questions/1228466/…