[英]How can I copy file from local server to remote with creating directories which absent via SSH?
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
, ie script must be light moveable without any changes. 最简单的方法意味着我只能通过$PWD
来获取当前路径,即脚本必须轻便地移动而没有任何更改。
这个命令可以做到:
rsync -ahHv --rsync-path="mkdir -p $PWD && rsync" filename -e "ssh -v" root@192.168.0.19:"$PWD/"
I can make the same directories on the remote servers and copy file to it via SSH by using SCP like this: 我可以在远程服务器上创建相同的目录,并通过使用SCP的方式通过SSH将文件复制到其中:
cd /root/dir1/dir2/
ssh -n root@192.168.0.19 "mkdir -p '$PWD'"
scp -p filename root@192.168.0.19:$PWD/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.