[port] scp with port number specified

I'm trying to scp a file from a remote server to my local machine. Only port 80 is accessible.

I tried:

scp -p 80 [email protected]:/root/file.txt .

but got this error: cp: 80: No such file or directory

How do I specify the port number in a scp command?

This question is related to port scp

The answer is


To backup all files in all directories to a remote Synology NAS using a different remote port:

scp -P 10022 -r /media/data/somedata/* [email protected]:/var/services/homes/user/directory/


You know what's cooler than -P? nothing

If you use this server more than a few times, setup/create a ~/.ssh/config file with an entry like:

Host www.myserver.com
    Port 80

or

Host myserver myserver80 short any.name.u.want yes_anything well-within-reason
    HostName www.myserver.com
    Port 80
    User username

Then you can use:

scp [email protected]:/root/file.txt .

or

scp short:/root/file.txt .

You can use anything on the "Host" line with ssh, scp, rsync, git & more

There are MANY configuration option that you can use in config files, see:

man ssh_config


There are many answers, but you should just be able to keep it simple. Make sure you know what port SSH is listening on, and define it. Here is what I just used to replicate your problem.

scp -P 12222 file.7z [email protected]:/home/user/Downloads It worked out well.


Copying file to host: scp SourceFile remoteuser@remotehost:/directory/TargetFile

Copying file from host: scp user@host:/directory/SourceFile TargetFile

Copying directory recursively from host: scp -r user@host:/directory/SourceFolder TargetFolder

NOTE: If the host is using a port other than port 22, you can specify it with the -P option: scp -P 2222 user@host:/directory/SourceFile TargetFile


scp help tells us that port is specified by uppercase P.

~$ scp
usage: scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
           [-l limit] [-o ssh_option] [-P port] [-S program]
           [[user@]host1:]file1 ... [[user@]host2:]file2

Hope this helps.


Hope this will help someone looking for a perfect answer

Copying a folder or file from a server with a port defined to another server or local machine

  1. Go to a directory where you have admin rights preferably your home directory on the machine where you want to copy files to
  2. Write the command below

scp -r -P port user@IP_address:/home/file/pathDirectory .

**Note:** The last . on the command directs it to copy everything in that folder to your directory of preference

This can be achived by specifying port via the -P switch:

scp -i ~/keys/yourkey -P2222 file ubuntu@host:/directory/

One additional hint. Place the '-P' option after the scp command, no matter whether the machine you are ssh-ing into is the second one (aka destination). Example:

scp -P 2222 /absolute_path/source-folder/some-file [email protected]:/absolute_path/destination-folder

if you need copy local file to server (specify port )

scp -P 3838 /the/source/file [email protected]:/destination/file

for use another port on scp command use capital P like this

scp -P port-number source-file/directory user@domain:/destination

ya ali


I'm using different ports then standard and copy files between files like this:

scp -P 1234 user@[ip address or host name]:/var/www/mywebsite/dumps/* /var/www/myNewPathOnCurrentLocalMachine

This is only for occasional use, if it repeats itself based on a schedule you should use rsync and cron job to do it.