I can copy file via SSH by using SCP like this:
我可以像这样使用SCP来通过SSH复制文件:
cd /root/dir1/dir2/
scp filename root@192.168.0.19:$PWD/
But if on remote server some directories are absent, in example remote server has only /root/ and havn't dir1 and dir2, then I can't do it and I get an error.
但是如果在远程服务器上某些目录不存在,例如远程服务器只有/ root /并且没有dir1和dir2,那么我不能这样做而且我收到错误。
How can I do this - to copy file with creating directories which absent via SSH, and how to make it the easiest way?
我该怎么做 - 复制文件创建目录,通过SSH不存在,以及如何使它成为最简单的方法?
The easiest way mean that I can get current path only by $PWD
, i.e. script must be light moveable without any changes.
最简单的方法意味着我只能通过$ PWD获得当前路径,即脚本必须是轻微可移动的而不做任何更改。
2 个解决方案
#1
1
This command will do it:
这个命令会这样做:
rsync -ahHv --rsync-path="mkdir -p $PWD && rsync" filename -e "ssh -v" root@192.168.0.19:"$PWD/"
#2
0
I can make the same directories on the remote servers and copy file to it via SSH by using SCP like this:
我可以在远程服务器上创建相同的目录,并通过SSH使用SCP将文件复制到它:
cd /root/dir1/dir2/
ssh -n root@192.168.0.19 "mkdir -p '$PWD'"
scp -p filename root@192.168.0.19:$PWD/
#1
1
This command will do it:
这个命令会这样做:
rsync -ahHv --rsync-path="mkdir -p $PWD && rsync" filename -e "ssh -v" root@192.168.0.19:"$PWD/"
#2
0
I can make the same directories on the remote servers and copy file to it via SSH by using SCP like this:
我可以在远程服务器上创建相同的目录,并通过SSH使用SCP将文件复制到它:
cd /root/dir1/dir2/
ssh -n root@192.168.0.19 "mkdir -p '$PWD'"
scp -p filename root@192.168.0.19:$PWD/