Scp with specified port number

This article was translated from: scp with port number specified

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

I tried: I tried:

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

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

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


#1st Floor

Reference: https://stackoom.com/question/hOAq/ scp with specified port number


#2nd Floor

Unlike ssh, scp uses the uppercase P switch to set the port instead of the lowercase p: Unlike ssh, scp uses the uppercase P switch to set the port instead of 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. The lowercase p switch is used with scp to save time and mode.

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: The following is an excerpt from the scp man page , which contains all the details about the two switches , And the explanation of the reason for choosing uppercase P for scp:

-P port specifies the port to connect to on the remote host. -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). Please note that this option is written in uppercase "P" because -p has Reserved is used to keep the time and mode of the file in rcp (1).

-p Preserves modification times, access times, and modes from the original file. -p Preserve the modification time, access time and mode of the original file .

Update and aside to address one of the (heavily upvoted) comments : Update and address one of the (heavy upvoted) comments :

With regard to Abdull's comment about scpoption order, what he suggests: Regarding Abdull's comment about option order , he suggested:scp

scp -P80 -r some_directory -P 80 ...

..., intersperses options and parameters. ..., intersperses options and parameters. Clearly define getopt(1)that parameters must come after options and not be interspersed with them: Clearly define parameters must come after options and not be interspersed with them getopt(1):

The parameters getopt is called with can be divided into two parts: options which modify the way getopt will do the parsing (the options and the optstring in the SYNOPSIS), and the parameters which are to be parsed (parameters in the SYNOPSIS). Calls The parameter getopt can be divided into two parts: options that modify the way getopt will parse (options and optstring in SYNOPSIS), and parameters to be parsed (parameters in SYNOPSIS). The second part will start at the first non-option parameter that is not an option argument, or after the first occurrence of '-'. The second part will start at the first non-option parameter, which is not an option parameter, or After the first occurrence of '-'. If no '-o' or '--options' option is found in the first part, the first parameter of the second part is used as the short options string. If "-o" or "- options ”, the first parameter of the second part will be used as the short option string.

Since the -rcommand line option takes no further arguments, some_directoryis "the first non-option parameter that is not an option argument." Since the -rcommand line option no longer uses other parameters, it some_directoryis "the first non-option parameter of the non-option parameter" . Therefore, as clearly spelled out in the getopt(1)man page, all succeeding command line arguments that follow it (ie, -P 80 ...) are assumed to be non-options (and non-option arguments). Therefore, as getopt(1)clearly stated in the man page , All subsequent command-line parameters (ie -P 80 ...) that follow it are assumed to be non-options (and non-option parameters).

So, in effect, this is how getopt(1)sees the example presented with the end of the options and the beginning of the parameters demarcated by succeeding text bing in gray: So, in fact, this is getopt(1)the end of the examples and options seen The beginning of the parameters of the subsequent text bing division:

scp -P80 -r some_directory -P 80 ... scp -P80 -r some_directory -P 80 ...

Nothing has to do with the this scpbehavior and Everything to do with POSIX Standard Applications How the parse a using the Command Line Options at The getopt(3)the SET of C Functions. This scphas nothing to do behavior, and also how to use the POSIX standard application getopt(3)set of C functions to parse the command-line options related.

For more details with regard to command line ordering and processing, please read the getopt(1)manpage using: For more detailed information about command line ordering and processing, please read the online help page:getopt(1)

man 1 getopt

#3rd floor

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

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. This is only for occasional use, if it repeats according to schedule, you should use rsync and cron job to perform this operation .


#4th floor

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

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

Copying directory recursively from host: scp -r user@host:/directory/SourceFolder TargetFolder Recursively copy the directory from the 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 Note : If the host uses a port other than port 22, you can use the -P option to specify it:scp -P 2222 user@host:/directory/SourceFile TargetFile


#5th Floor

scp help tells us that port is specified by uppercase P. scp help tells us that the port is specified by capital 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 helps .


#6th floor

One additional hint. 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). Place the '-P' option after the scp command , regardless of whether the machine you are entering is Is the second one (that is, the destination). Example: Example:

scp -P 2222 /absolute_path/source-folder/some-file [email protected]:/absolute_path/destination-folder
Published 0 original articles · praised 8 · 30,000+ views

Guess you like

Origin blog.csdn.net/asdfgh0077/article/details/105486735