如何在通过 SSH 连接时复制本地文件夹中的文件?
该命令完美运行,但仅当我在本地运行它时:
scp /home/josh/Desktop/DATA/import/file001.csv root@10.0.3.14:/var/www/html/project
Run Code Online (Sandbox Code Playgroud)
我想通过 ssh 连接来启动它以获得相同的结果,这可能吗?
您可以在您的.ssh/config
ControlMaster auto
ControlPath ~/.ssh/control:%h:%p:%r
Run Code Online (Sandbox Code Playgroud)
然后使用 ssh 命令模式,它将重用现有连接:
将 ssh 会话推送到后台的解决方案:
local$ ssh remote
remote$ ~^Z # Shift+`, Ctrl+z - Push ssh into background
local$ scp file remote:/remotepath
local$ fg
remote$
Run Code Online (Sandbox Code Playgroud)
您还可以通过以下方式打开隧道:
remote$ ~C # Shift+`, Shift+c - Enter command mode
ssh> -R15000:localhost:22 # tunnel to local:22 from remote:15000
Forwarding port.
remote$ scp -P15000 localhost:/filepath ~/
remote$ ~C
ssh> -KR15000
Canceled forwarding.
remote$
Run Code Online (Sandbox Code Playgroud)