479

我正在命令行上通过 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]上传?

4

4 回答 4

770

你需要在scp某个地方做点什么。你有scp ./styles/,所以你说的是安全副本./styles/,但不是复制到哪里。

一般来说,如果你想下载,它会去:

# download: remote -> local
scp user@remote_host:remote_file local_file 

wherelocal_file实际上可能是放置您要复制的文件的目录。要上传,则相反:

# upload: local -> remote
scp local_file user@remote_host:remote_file

如果要复制整个目录,则需要-r. 可以想象scp为 like cp,除了您可以指定一个文件user@remote_host:file以及本地文件。

编辑:如评论中所述,如果本地和远程主机上的用户名相同,则在指定远程文件时可以省略用户。

于 2008-12-05T12:51:02.067 回答
172

如果复制到/从您的桌面计算机,请使用 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
于 2008-12-05T12:57:03.040 回答
23

您需要同时指定源和目标,如果要复制目录,则应查看 -r 选项。

因此,要递归地将 /home/user/whatever 从远程服务器复制到您的当前目录:

scp -pr user@remoteserver:whatever .
于 2008-12-05T13:25:00.487 回答
20

不,您仍然需要以scp [from] [to]任何方式复制

不同的是,你需要scp -p server:serverpath localpath

于 2008-12-05T12:49:36.207 回答