我正在命令行上SSH到远程服务器,并尝试使用scp
命令将目录复制到我的本地计算机上。 但是,远程服务器返回此“使用”消息:
[Stewart:console/ebooks/discostat] jmm% scp -p ./styles/
usage: scp [-1246BCEpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
[-l limit] [-o ssh_option] [-P port] [-S program]
[[user@]host1:]file1 [...] [[user@]host2:]file2
[Stewart:console/ebooks/discostat] jmm%
我希望能够在两个方向上传输文件。 从我读到的,我认为上面的命令可以下载, scp -p [localpath] [remotepath]
上传?
#1楼
不,你仍然需要scp [from] [to]
你复制的方式
不同的是,你需要scp -p server:serverpath localpath
#2楼
你需要在某个地方scp
。 你有scp ./styles/
,所以你说安全副本./styles/
,但不是在哪里复制它。
一般来说,如果你想下载,它将会:
# download: remote -> local
scp user@remote_host:remote_file local_file
其中local_file
实际上可能是放置您正在复制的文件的目录。要上传,则相反:
# upload: local -> remote
scp local_file user@remote_host:remote_file
如果要复制整个目录,则需要-r
。 可以将scp
视为cp
,除了可以使用user@remote_host:file
以及本地文件指定文件。
编辑:如注释中所述,如果本地和远程主机上的用户名相同,则在指定远程文件时可以省略用户。
#3楼
如果要复制到桌面计算机或从桌面计算机复制,请使用WinSCP,或者如果在Linux上,Nautilus通过“连接到服务器”选项支持SCP。
scp只能将文件复制到运行sshd的计算机上,因此您需要从运行scp的远程计算机上运行客户端软件。
如果在命令行上复制,请使用:
# copy from local machine to remote machine
scp localfile user@host:/path/to/whereyouwant/thefile
要么
# copy from remote machine to local machine
scp user@host:/path/to/remotefile localfile
#4楼
您需要指定源和目标,如果要复制目录,则应查看-r选项。
因此,从远程服务器递归复制/ home / user /以及当前目录:
scp -pr user@remoteserver:whatever .
来源:oschina
链接:https://my.oschina.net/stackoom/blog/3161436