with - scp tcp port

scp with port number specified (6)

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?

Copying file to host: scp SourceFile [email protected]:/directory/TargetFile

Copying file from host: scp [email protected]:/directory/SourceFile TargetFile

Copying directory recursively from host: scp -r [email protected]:/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 [email protected]:/directory/SourceFile TargetFile

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

scp -P 1234 [email protected][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.

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

scp -i ~/keys/yourkey -P2222 file [email protected]:/directory/

Unlike ssh, scp uses the uppercase P switch to set the port instead of the lowercase p:

scp -P 80 ... # Use port 80 to bypass the firewall, instead of the scp default

The lowercase p switch is used with scp for the preservation of times and modes.

Here is an excerpt from scp's man page with all of the details concerning the two switches, as well as an explanation of why uppercase P was chosen for scp:

-P port   Specifies the port to connect to on the remote host. Note that this option is written with a capital 'P', because -p is already reserved for preserving the times and modes of the file in rcp(1).

-p           Preserves modification times, access times, and modes from the original file.

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

scp -P port-number source-file/directory [email protected]:/destination

ya ali

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

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