Linux 如何使用SSH从服务器下载文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9427553/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to download a file from server using SSH?
提问by NiLL
I need to download a file from server to my desktop. (UBUNTU 10.04) I don't have a web access to the server, just ssh.
我需要从服务器下载一个文件到我的桌面。(UBUNTU 10.04) 我没有服务器的网络访问权限,只有 ssh。
If it helps, my OS is Mac OS X and iTerm 2 as a terminal.
如果有帮助,我的操作系统是 Mac OS X 和 iTerm 2 作为终端。
采纳答案by Josh1billion
In your terminal, type:
在您的终端中,键入:
scp [email protected]:foobar.txt /local/dir
replacing the username, host, remote filename, and local directory as appropriate.
根据需要替换用户名、主机、远程文件名和本地目录。
If you want to access EC2 (or other service that requires authenticating with a private key), use the -i
option:
如果要访问 EC2(或其他需要使用私钥进行身份验证的服务),请使用以下-i
选项:
scp -i key_file.pem [email protected]:/remote/dir/foobar.txt /local/dir
回答by J-16 SDiZ
If the SSH server support SFTP subsystem (this is part of SSH, and unrelatedto FTP), use sftp. If it don't, try scp.
如果 SSH 服务器支持 SFTP 子系统(这是 SSH 的一部分,与FTP无关),请使用 sftp。如果没有,请尝试 scp。
CyberDucksupport all of them.
CyberDuck支持所有这些。
回答by raj_gt1
You can do this with the scp
command. scp
uses the SSH protocol to copy files across system by extending the syntax of cp
.
您可以使用scp
命令执行此操作。scp
通过扩展 .ssh 的语法,使用 SSH 协议跨系统复制文件cp
。
Copy something from another system to this system:
从另一个系统复制一些东西到这个系统:
scp username@hostname:/path/to/remote/file /path/to/local/file
Copy something from this system to some other system:
将某些内容从此系统复制到其他系统:
scp /path/to/local/file username@hostname:/path/to/remote/file
Copy something from some system to some other system:
从某个系统复制一些东西到另一个系统:
scp username1@hostname1:/path/to/file username2@hostname2:/path/to/other/file
回答by William Pursell
scp is certainly the way to go, but for completeness you can also do:
scp 当然是要走的路,但为了完整起见,你也可以这样做:
$ ssh host 'cat /path/on/remote' > /path/on/local
or
或者
$ cat /path/on/local | ssh host 'cat > /path/on/remote'
Note, this is UUOC, but < /path/on/local ssh host 'cat > /path'
could cause unnecessary confusion.
请注意,这是 UUOC,但< /path/on/local ssh host 'cat > /path'
可能会导致不必要的混淆。
And to proxy between two hosts:
并在两台主机之间进行代理:
$ ssh host1 'cat /path/on/host1' | ssh host2 'cat > /path/on/host2'