Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to copy file from my server to another so I am using the following command:

scp root@myhost /home/direc/file.tar username@secondhost:/home/dir

I am getting the error:

ssh: connect to host secondhost port 22 connection timed out

I know it might be because port 22 is not open on second host

so How do I transfer by specifying port 21 on my second host

share|improve this question
up vote 7 down vote accepted


scp -P 21 root@myhost /home/direc/file.tar username@secondhost:/home/dir

Where -P stands for port number.

share|improve this answer
I know this but it specifies the port for first host from where I want to copy files not the second host.So do I specify port 21 for second host – user1613566 Aug 31 '12 at 6:51

Two flaws I see in your attempt and the response.

1) scp is a secure shell (ssh) utility for securely copying files between hosts. It uses ssh for data transfer and uses the same authentication and provides the same security as ssh (see scp manpage). By default, ssh uses port 22. So unless you changed the default port number for ssh on the destination server to 21, or you have not installed and started the ssh server (sshd) on the receiving server, you can not use scp to copy files.

2) The proper command line from your example should be:

scp -P '*port running ssh on destination server*' /home/direc/file.tar username@remotehost:/home/dir

The first root@myhost is not necessary and will in fact attempt to copy a file named root@myhost (that most likely does not exist) and file.tar to the destination server. You most likely will receive the message:

root@myhost: No such file or directory during the copy.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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