Scp times out but ssh works fine. What am I doing wrong


ssh works fine but scp doesn't work at all. Am I making a syntactical error?

$ scp ~/Downloads/EWBF.tar.gz -P 1312
ssh: connect to host port 22: Operation timed out
lost connection
$ ssh -p 1312's password: 
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-104-generic x86_64)

My server sits behind a home router in a different city with DDNS and port forwarding set up from external ports 1312 and 1313 both mapping on to port 22 for the MAC addresses of the ethernet and wifi card, respectively. The server is currently using the ethernet connection (port 1312) but used to be connected via wifi. I used to have no problem using scp when the wifi was active, but it's been a while and I'm not entirely certain that I haven't made some kind of syntactic error. I've been working on trying to access the router's web interface remotely to double check the settings but haven't managed yet (any advice on this would also be appreciated!)

Best Answer

This argument ~/Downloads/EWBF.tar.gz causes scp to stop parsing options. -P and 1312 are then treated as files to be sent. Therefore scp tries to connect to default port 22, as you can see here:

ssh: connect to host port 22: Operation timed out

Option(s) should precede filename(s):

scp -P 1312 ~/Downloads/EWBF.tar.gz