如何使用scp将文件夹从远程主机复制到本地主机?
我使用ssh登录到我的服务器。然后,我想将远程文件夹foo复制到local/home/user/Desktop。
我如何做到这一点?
如何使用scp将文件夹从远程主机复制到本地主机?
我使用ssh登录到我的服务器。然后,我想将远程文件夹foo复制到local/home/user/Desktop。
我如何做到这一点?
当前回答
要使用scp的全部功能,您需要执行以下步骤:
公钥授权创建SSH别名
然后,例如,如果您有这个~/.ssh/config:
Host test
User testuser
HostName test-site.example
Port 22022
Host prod
User produser
HostName production-site.example
Port 22022
您将省去密码输入,并简化scp语法,如下所示:
scp -r prod:/path/foo /home/user/Desktop # copy to local
scp -r prod:/path/foo test:/tmp # copy from remote prod to remote test
此外,您还可以使用远程路径完成:
scp test:/var/log/ # press tab twice
Display all 151 possibilities? (y or n)
为了实现远程bash完成,您需要在<source>和<target>主机上都有bash shell,并正确地运行bash完成。有关更多信息,请参阅相关问题:
使用scp时如何启用远程路径的自动完成?SCP文件名选项卡完成
其他回答
我不知道为什么,但我必须在源服务器指令之前使用本地文件夹。让它发挥作用
scp -r . root@888.888.888.888:/usr/share/nginx/www/example.org/
这个问题的前提是不正确的。其想法是,一旦登录ssh,如何将文件从登录的计算机移回登录的客户端。然而,scp不知道,也不能使用ssh连接。它正在建立自己的联系。因此,简单的解决方案是在本地工作站上创建一个新的终端窗口,并运行scp,将文件从远程服务器传输到本地计算机。例如,scp-i键user@remote:/remote dir/remote file/local dir/local file
如果遇到“太多身份验证失败”,请指定添加到服务器SSH服务器的确切SSH密钥:
scp -r -i /path/to/local/key user@remote.tld:/path/to/folder /your/local/target/dir
转到统一工具栏上的文件
按Ctrl+l并写入here_goes_your_user_name@192.168.10.123
192.168.1.103是您要连接的主机。
这里有一个例子
要使用scp的全部功能,您需要执行以下步骤:
公钥授权创建SSH别名
然后,例如,如果您有这个~/.ssh/config:
Host test
User testuser
HostName test-site.example
Port 22022
Host prod
User produser
HostName production-site.example
Port 22022
您将省去密码输入,并简化scp语法,如下所示:
scp -r prod:/path/foo /home/user/Desktop # copy to local
scp -r prod:/path/foo test:/tmp # copy from remote prod to remote test
此外,您还可以使用远程路径完成:
scp test:/var/log/ # press tab twice
Display all 151 possibilities? (y or n)
为了实现远程bash完成,您需要在<source>和<target>主机上都有bash shell,并正确地运行bash完成。有关更多信息,请参阅相关问题:
使用scp时如何启用远程路径的自动完成?SCP文件名选项卡完成