本文介绍了通过 SSH 传输文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在命令行上通过 SSH 连接到远程服务器,并尝试使用 scp 命令将目录复制到我的本地机器上.但是,远程服务器返回此使用"消息:

I'm SSHing into a remote server on the command line, and trying to copy a directory onto my local machine with the scp command. However, the remote server returns this "usage" message:

[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] 用于上传?

I'd like to be able to transfer files in both directions. From what I read, I thought the above command would work for downloading, and scp -p [localpath] [remotepath] for uploading?

推荐答案

你需要在某处scp.你有 scp ./styles/,所以你说的是安全复制 ./styles/,但不是复制到哪里.

You need to scp something somewhere. You have scp ./styles/, so you're saying secure copy ./styles/, but not where to copy it to.

一般来说,如果你要下载,就去:

Generally, if you want to download, it will go:

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

其中 local_file 实际上可能是一个用于放置您要复制的文件的目录.要上传,则相反:

where local_file might actually be a directory to put the file you're copying in. To upload, it's the opposite:

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

如果你想复制整个目录,你需要-r.将 scp 视为与 cp 类似,除了您可以使用 user@remote_host:file 指定文件以及仅本地文件.

If you want to copy a whole directory, you will need -r. Think of scp as like cp, except you can specify a file with user@remote_host:file as well as just local files.

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

As noted in a comment, if the usernames on the local and remote hosts are the same, then the user can be omitted when specifying a remote file.

这篇关于通过 SSH 传输文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 22:45