如何创建远程主机上的目录,如果没有-ING在SSH不存在呢? [英] How do I create a directory on remote host if it doesn't exist without ssh-ing in?

查看:221
本文介绍了如何创建远程主机上的目录,如果没有-ING在SSH不存在呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这是可能的或没有。基本上,我正在写一个脚本,可以让我 SCP 文件到我的主机。这是它迄今。参数1是文件和论证2是我希望它被放置在远程服务器上的文件夹:

I'm not sure if this is possible or not. Basically, I'm writing a script that allows me to scp a file to my hosting. This is it so far. Argument 1 is the file and argument 2 is the folder I want it to be placed in on the remote server:

function upload {
    scp $1 myusername@ssh.myhost.net:$2
}

你可能/可能不知道,如果当我打电话的功能我指定的目录不存在,那么传输失败。有没有一种方法来检查,如果在函数存在,如果它不,创建它的目录。

As you may/may not know, if the directory I specify when I call the function doesn't exist, then the transfer fails. Is there a way to check if the directory exists in the function and if it doesn't, create it.

我$不必在每次ssh和创建目录p $ PFER,但如果我有没有选择,那么我有没有选择。

I would prefer not having to ssh in every time and create the directory, but if I have got no choice, then I have got no choice.

推荐答案

您可以使用rsync。

You can use rsync.

例如,

rsync -ave ssh fileToCopy ssh.myhost.net:/some/nonExisting/dirToCopyTO

请注意有关rsync的:

Note about rsync:

rsync的是实用软件和用于Unix哪些文件和目录进行同步从一个位置到另一个网络协议而通过使用增量编码使用rsync的算法比其它工具,更快适当时最大限度地减少数据传输。

rsync is utility software and network protocol for Unix which synchronizes files and directories from one location to another while minimizing data transfer by using delta encoding when appropriate using the rsync algorithm which is faster than other tools.

这篇关于如何创建远程主机上的目录,如果没有-ING在SSH不存在呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆