指定端口号的scp [英] scp with port number specified

查看:888
本文介绍了指定端口号的scp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文件从远程服务器发送到本地计算机.只能访问端口80.

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

我尝试过:

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

但出现此错误:cp: 80: No such file or directory

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

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

推荐答案

与ssh不同,scp使用大写的P开关设置端口,而不是小写的p:

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

小写的p开关与scp一起用于保存时间和模式.

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

这里摘录自scp的手册页,其中包含有关两个开关的所有详细信息,并解释了为什么为scp选择大写P:

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端口指定要连接到远程主机上的端口.请注意,此选项使用大写字母"P"编写,因为-p已经存在 保留用于在rcp(1)中保留文件的时间和模式.

-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         保留原始文件的修改时间,访问时间和模式.

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

更新并放在一旁(严重反对)评论:

关于阿卜杜勒对scp期权订单的评论,他的建议是:

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

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

...,插入选项和参数. getopt(1)清楚地定义了参数必须在选项之后,并且不能与它们一起使用:

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

调用getopt的参数可以分为两部分:修改getopt进行解析的方式的选项(SYNOPSIS中的选项和optstring)以及要解析的参数(SYNOPSIS中的参数) ).第二部分将从 不是选项参数的第一个非选项参数,或者在第一次出现-"之后.如果在第一部分中没有找到'-o'或'--options'选项,则第二部分的第一个参数将用作简短选项字符串.

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

由于-r命令行选项不包含其他参数,因此some_directory是第一个非选项参数,而不是选项参数".因此,如getopt(1)手册页中明确指出的那样,所有紧随其后的命令行参数(即-P 80 ...)都假定为非选项(和非选项参数).

Since the -r command line option takes no further arguments, some_directory is "the first non-option parameter that is not an option argument." Therefore, as clearly spelled out in the getopt(1) man page, all succeeding command line arguments that follow it (i.e., -P 80 ...) are assumed to be non-options (and non-option arguments).

因此,实际上,这是getopt(1)如何看待示例的示例,该示例显示了选项的末尾和参数的开头,并以灰色的文本bing划出了界限:

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:

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

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

这与scp行为无关,并且与POSIX标准应用程序使用getopt(3)组C函数解析命令行选项有关.

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.

有关命令行顺序和处理的更多详细信息,请使用以下内容阅读getopt(1)手册页:

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

man 1 getopt

这篇关于指定端口号的scp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆