Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

port - 指定端口号的scp(scp with port number specified)

I'm trying to scp a file from a remote server to my local machine.

(我正在尝试将文件从远程服务器scp到我的本地计算机。)

Only port 80 is accessible.

(只有80端口可以访问。)

I tried:

(我试过了:)

scp -p 80 username@www.myserver.com:/root/file.txt .

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

(但得到了这个错误: cp: 80: No such file or directory)

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

(如何在scp命令中指定端口号?)

  ask by One Two Three translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

(与ssh不同,scp使用大写P开关来设置端口而不是小写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.

(小写p开关与scp一起用于保存时间和模式。)

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:

(以下是scp手册页的摘录,其中包含有关两个开关的所有详细信息,以及为scp选择大写P的原因解释:)

-P port Specifies the port to connect to on the remote host.

(-P port指定要在远程主机上连接的端口。)

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”编写,因为-p已保留用于保留rcp(1)中文件的时间和模式。)

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

(-p保留原始文件的修改时间,访问时间和模式。)

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

(更新并在旁边解决其中一个(大量投票)评论 :)

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

(关于Abdull关于scp期权订单的评论,他建议:)

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

..., intersperses options and parameters.

(......,散布选项和参数。)

getopt(1) clearly defines that 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).

(调用参数getopt可以分为两部分:修改getopt将进行解析的方式的选项(SYNOPSIS中的选项和optstring),以及要解析的参数(SYNOPSIS中的参数)。)

The second part will start at the first non-option parameter that is not an option argument, 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.

(如果在第一部分中未找到“-o”或“--options”选项,则第二部分的第一个参数将用作短选项字符串。)

Since the -r command line option takes no further arguments, some_directory is "the first non-option parameter that is not an option argument."

(由于-r命令行选项不再使用其他参数,因此some_directory是“第一个非选项参数的非选项参数”。)

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).

(因此,正如在getopt(1)手册页中清楚地说明的那样,跟随它的所有后续命令行参数(即-P 80 ... )都被假定为非选项(和非选项参数)。)

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:

(因此,实际上,这就是getopt(1)看到的示例与选项的结尾以及由灰色的后续文本bing划分的参数的开头:)

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

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

This has nothing to do with scp behavior and everything to do with how POSIX standard applications parse command line options using the getopt(3) set of C functions.

(这与scp行为无关,也与POSIX标准应用程序如何使用getopt(3) C函数集解析命令行选项有关。)

For more details with regard to command line ordering and processing, please read the getopt(1) manpage using:

(有关命令行排序和处理的更多详细信息,请阅读getopt(1)联机帮助页:)

man 1 getopt

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...