SSH and FTP via Dropbox

    Good luck to all!

    Today I will tell you, dear habralum, about one crazy idea that came to my head and even embodied in life.

    Attention! All of the following is not a guide to action and to perceive it is nothing more than humor . And then it was painfully taken seriously by everyone ... =)

    To begin with, a little background. Recently, there was a very urgent need for ssh access to some unix-based computer in order to run theresvn diff > mypatch.diffand transfer the result to ftp. But it turned out that the target machine for some reason does not want to ping! Moreover, according to admins, ping for it is not expected, although it has Internet access. And I decided that it would be nice to forward ssh through something third-party. VPN, reverse ssh, tunnels, etc., immediately began to climb into my head. But for most solutions, you need an additional machine and / or additional software, or it requires reconfiguring the network itself (which is not an option for me at all - the network is not mine). I was already ready to despair and google more persistently, but then the thought came to my not-so-healthy head: what if I dropped a dropbox?

    Actually, the idea is extremely simple. In the dropbox, make a folder for which the script monitors the target machine. And when you find the right file in it (in my case -*.sh), launches it, redirecting stdout and stderr to a text file. And that text file again throws it to the dropbox, but to another daddy.

    As a result, something like this came out: in the dropbox there are shell_in, shell_out and shell_done folders. The script monitors the first folder, when it detects a script, moves it to a temporary folder, adds a date-time to the name, executes, writes the output to a file and throws it to shell_out, and moves the executed script to shell_done, for history.

    The script itself, which we will throw, can do anything that does not require user interaction. For example, copying some files to the dropbox - here is a certain analogue of FTP drew!

    Pros and cons of this method:

    + only the dropbox and the connection to the network are required from the target system
    +scripts are executed on behalf of the user under whom the daemon is launched
    + flexibility of the approach, it can be easily ported to any OS
    + scripts can be run from anywhere where there is a text editor and dropbox

    - goodbye MC = (
    - low file transfer speed compared to ftp
    - there is no way to run scripts via sudo
    - never realtime
    - even for the simplest commands you need to create a script
    - to see the output of the application, you have to read a text file
    - and indeed this way is nonsense, but cool =)

    In general, I decided to implement this business. I chose a shell script as a tool. I did not find a good platform-independent way of tracking the file system right away, so I decided to check for files in an infinite loop with sleep5 seconds. If someone tells me a good way not to do this, I will be grateful.

    The code is trivial, but just in case I post it on github - what if it comes in handy to whom?

    The plans are to make an analogue for windows, a daemon on batch, which is also looking for batch files. The best thing is to rewrite everything in C ++ or Python - for platform independence (and at the same time to use platform notifiers about file changes).

    PS : all of the above is done just for fun, for real work, using this method is not recommended for security reasons, it is better to use something more secure, such as xmpp-ssh , or other good things.

    Also popular now: