0

I'm using SCP to backup files from my VPS in the cloud to my PC. In an early version of the backup script there is one single SCP command to backup everything from the server root. This works flawlessly..

However, as the server grows, this is starting to get big so I'm changing the script to run SCP commands on specific directories (about a dozen). And now some of the individual SCP commands fail at random with "connections refused". But the next SCP command in the script works... I have added a 5-second delay between each SCP command in case there is some throttling somewhere but this is not enough.

What can be causing this? What can I check?

netstat on the server after the script has run shows several ssh connections from my IP (including of course the connections to issue netstat but this would only be one o f them?).

In case it matters the server is running Ubuntu Server 16.04 and my PC runs Ubuntu 14.04.

  • would not rsync do better job? – Jakuje Dec 17 '16 at 14:00
0

Most probably your VPS provider (or your own server) limits the rate of ssh connections. Once the rate limit is passed, your connection is refused.

[update]

If this limit is on your VPS provider side, you can overcome it by establishing an ssh tunnel (i.e. ssh -L 2222:localhost:22 user@vps) to your server for the duration of your script, and then scp-ing exclusively via this tunnel (i.e. via localhost:2222 with the tunnel I gave).

  • The code is already laced with sleep 5 commands but that isn't enough (editing the question to mention this). If this is a server limit, where can I check/change it? – xenoid Dec 17 '16 at 14:02
  • @xenoid I have amended my answer – xhienne Dec 17 '16 at 14:11
  • So, the UFW firewall indeed limits the SSH connections, so I'll see if I can lif the limits for a couple of IPs, oherwise I'll look into your tunnel connection. – xenoid Dec 17 '16 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.