How do I create a directory on remote host if it doesn't exist without ssh-ing in?

后端 未结 6 2031
南笙
南笙 2021-02-01 00:57

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 i

6条回答
  •  轮回少年
    2021-02-01 01:46

    sshfs be fancy!

    Example .ssh/config

    Host your-host
      HostHame example.com
      User name
      IdentitiesOnly yes
      IdentityFile ~/.ssh/private_key
    

    Local setup aside from above only requires a target mount point...

    sudo mkdir /media/your-host
    sudo chown ${USER}:${USER} /media/your-host
    

    ... after which things like mounting and un-mounting are far simpler to script.

    Mount

    sshfs your-host:within-home/some-dir /media/your-host
    

    Unmount

    fusermount -u /media/your-host
    

    Best part about this approach, when a server allows it, is that locally running scripts can interact with the remote file system. Meaning that things like...

    if ! [ -d "/media/your-host/nowhere" ]; then
      mkdir -vp "/media/your-host/nowhere"
    fi
    

    ... become possible among many other tricks that can be preformed via such mounting magics.

提交回复
热议问题