2023-04-14 05:00:00

指定端口号的SCP

我试图scp文件从远程服务器到我的本地机器。只有80端口可访问。

我试着:

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

cp: 80:没有这样的文件或目录

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


当前回答

我使用不同的端口然后标准和复制文件之间的文件,像这样:

scp -P 1234 user@[ip address or host name]:/var/www/mywebsite/dumps/* /var/www/myNewPathOnCurrentLocalMachine

这只是偶尔使用,如果它根据计划重复自己,您应该使用rsync和cron作业来完成它。

其他回答

如果要在scp命令上使用另一个端口,请像这样使用大写P

scp -P port-number source-file/directory user@domain:/destination

是的,阿里

希望这对寻找完美答案的人有所帮助

将具有定义端口的服务器上的文件夹或文件复制到另一台服务器或本地计算机

转到您有管理权限的目录,最好是您想要复制文件的机器上的主目录 编写下面的命令

scp -r -P port user@IP_address:/home/file/pathDirectory。

**Note:** The last . on the command directs it to copy everything in that folder to your directory of preference

另外一个提示。将'-P'选项放在scp命令之后,无论您要ssh-ing到的机器是否是第二个机器(也就是目的地)。例子:

scp -P 2222 /absolute_path/source-folder/some-file user@example.com:/absolute_path/destination-folder

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

希望这能有所帮助。

如果需要将本地文件复制到服务器(指定端口)

scp -P 3838 /the/source/file username@server.com:/destination/file