📜 ⬆️ ⬇️

SSH and FTP via Dropbox

Good luck to everyone!

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

Attention! Everything described below is not a guide to action and perceive it is nothing but humor . But it hurt seriously everyone took it ... =)

First, a little background. Recently, there was a very urgent need for ssh access to some unix-based computer in order to run svn diff > mypatch.diff and svn diff > mypatch.diff result via ftp. But it turned out that the target machine for some reason does not want to ping! Moreover, according to the admins, they do not expect a ping for it, although it has Internet access. And I decided that it would be nice to send ssh through something third-party. VPN, reverse ssh, tunnels, and so on immediately began to creep into my head. But for most solutions, an additional machine and / or additional software is needed, or it requires reconfiguration of the network itself (which for me is not an option at all - the network is not mine). I was ready to despair and google stubbornly, but then the thought came to my not very healthy head: what if I use dropbox?

Actually, the idea is very simple. In the dropbox we make a folder that the script follows on the target machine. And when a necessary file is detected in it (in my case - *.sh ), it starts it by redirecting stdout and stderr to a text file. And the text file again throws in the dropbox, but in another daddy.
')
As a result, it turned out something like the following: dropbox has the shell_in, shell_out and shell_done folders. The script monitors the first folder, when a script is found, moves it to a temporary folder, adds the date-time to the name, executes, writes the output to a file and throws it to the shell_out, and the spent script moves to the shell_done, for history.

The script itself, which we are going to throw, can do anything that does not require user interaction. For example, copying certain files to the dropbox - that’s some kind of FTP analog!

Pros and cons of this method:

+ the target system only needs dropbox and connect to the network
+ scripts are executed on behalf of the user under which the daemon is running
+ flexibility of approach, 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 possibility 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 the text file
- and indeed such a method is nonsense, but cool =)

In general, I decided to implement this. I chose shell script as a tool. I didn’t find a good platform-independent way of tracking the file system, so I decided to check for the presence of files in an infinite loop with sleep in 5 seconds. If someone tells a good way not to do it, I will be grateful.

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

The plans - to make an analog for windows, a demon on batch, looking for batch file as well. Best of all is to rewrite everything in C ++ or Python - for platform independence (and at the same time to enable platform notifiers about file changes).

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

Source: https://habr.com/ru/post/142410/


All Articles