简体   繁体   English

如何通过创建不通过SSH的目录将文件从本地服务器复制到远程服务器?

[英]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.

相关问题 How ansible copy file from remote windows to remote linux without local copy and ssh install in windows - How ansible copy file from remote windows to remote linux without local copy and ssh install in windows 我该如何计划一个脚本,使用CRON和SCP每小时使用时间戳将文件从远程服务器复制到本地计算机? - How can I schedule a script to copy a file from a remote server to my local machine every hour with a time stamp using CRON & SCP? 如何通过ssh将命令行的输出从远程复制到本地剪贴板 - How to copy output of command line from remote, to local clipboard via ssh 如何使用 nohup 通过 ssh 在远程服务器上执行本地 bash 脚本 - How to execute a local bash script on remote server via ssh with nohup 如何使用 ssh 将远程服务器变量存储到本地服务器变量? - How can I store a remote server variable to local server variable with ssh? 当我通过 Git Bash 中的 ssh 在远程 Linux 机器上运行命令时,如何将文件的内容直接复制到我的 Windows 剪贴板中? - How can I copy the contents of a file directly into my Windows clipboard when I'm running the command on a remote Linux machine via ssh in Git Bash? 如何从远程ssh连接上运行的tmux(复制模式)复制到本地剪贴板 - How do you copy from tmux (copy mode) running on a remote ssh connection to your local clipboard 我无法通过本地phpmyadmin访问远程mysql服务器 - I can't access remote mysql server via local phpmyadmin 如何运行脚本以将日志从远程服务器复制到本地 - How to run script to copy logs from remote server to local 如何通过 SSH 访问远程(远程服务器上的本地 gitlab 实例)存储库? - How do I access a remote (local gitlab instance on remote server) repository over SSH?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM