指定端口号的scp
我正在尝试将文件从远程服务器scp到我的本地计算机。 只有80端口可以访问。
我试过了:
scp -p 80 username@www.myserver.com:/root/file.txt .
但得到了这个错误:cp: 80: No such file or directory
如何在scp命令中指定端口号?
One Two Three asked 2018-12-28T21:01:11Z
9个解决方案
1105 votes
与ssh不同,scp使用大写P开关来设置端口而不是小写p:
scp -P 80 ... # Use port 80 to bypass the firewall, instead of the scp default
小写p开关与scp一起用于保存时间和模式。
以下是scp手册页的摘录,其中包含有关两个开关的所有详细信息,以及为scp选择大写P的原因解释:
-P port指定要在远程主机上连接的端口。 请注意,此选项使用大写“P”编写,因为-p已经存在 保留用于保留rcp(1)中文件的时间和模式。
-p保留原始文件的修改时间,访问时间和模式。
Michael Goldshteyn answered 2018-12-28T21:01:46Z
45 votes
一个额外的提示。 在scp命令之后放置'-P'选项,无论你正在进入的机器是否是第二个(也就是目的地)。 例:
scp -P 2222 /absolute_path/source-folder/some-file user@example.com:/absolute_path/destination-folder
Gooshan answered 2018-12-28T21:02:09Z
37 votes
你知道什么比man ssh_config更酷吗? 没有
如果您多次使用此服务器,请使用以下条目设置/创建man ssh_config文件:
Host www.myserver.com
Port 80
要么
Host myserver myserver80 short any.name.u.want yes_anything well-within-reason
HostName www.myserver.com
Port 80
User username
然后你可以使用:
man ssh_config
要么
man ssh_config
您可以在“主机”行使用ssh,scp,rsync,git和amp; 更多
您可以在配置文件中使用许多配置选项,请参阅:
man ssh_config
Mike answered 2018-12-28T21:03:14Z
24 votes
我正在使用不同的端口然后标准并在文件之间复制文件,如下所示:
scp -P 1234 user@[ip address or host name]:/var/www/mywebsite/dumps/* /var/www/myNewPathOnCurrentLocalMachine
这仅适用于偶尔使用,如果它根据计划重复,您应该使用rsync和cron job来执行此操作。
Marian Zburlea answered 2018-12-28T21:03:51Z
4 votes
scp help告诉我们端口由大写字母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
希望这可以帮助。
D D answered 2018-12-28T21:04:20Z
2 votes
复制文件到主机:scp SourceFile remoteuser@remotehost:/directory/TargetFile
从主机复制文件:scp -P 2222 user@host:/directory/SourceFile TargetFile
从主机复制目录递归:scp -P 2222 user@host:/directory/SourceFile TargetFile
注意:如果主机使用端口22以外的端口,你可以用-P选项指定它:scp -P 2222 user@host:/directory/SourceFile TargetFile
AJ. answered 2018-12-28T21:05:04Z
1 votes
这可以通过-P开关指定端口来实现:
scp -i ~/keys/yourkey -P2222 file ubuntu@host:/directory/
Vaseem007 answered 2018-12-28T21:05:35Z
0 votes
如果需要将本地文件复制到服务器(指定端口)
scp -P 3838 /the/source/file username@server.com:/destination/file
Turan Zamanlı answered 2018-12-28T21:05:58Z
0 votes
使用scp命令的另一个端口使用大写P这样
scp -P port-number source-file/directory user@domain:/destination
你好阿里
Hasan Barary answered 2018-12-28T21:06:27Z