LINUX
Two More Unorthodox ways to transfer files
2017-04-19 | by David "DeMO" Martínez Oliveira
For many years I have successfully used the techniques described in Four Unorthodox Ways to Transfer Files, for my transfer need. But, recently, I found a case where none of those techniques worked. So I have to come up with innovative ways to deal with the that.
Let's introduce the scenario first. I have to transfer some files to an Android device. The device was physically inaccessible and the only way to access it was via SSH but, for some reason,
■
scp
didn't worked. There was no other kind of server (HTTP, FTP,...) and only SSH was possible.
Abusing SSH redirection to transfer files
So, the first and more straight forward option to transfer my files was to abuse the SSH redirection capabilities. Something like this:$ cat file.dat | ssh host "cat > /data/local/tmp/file.dat"This worked fine, but the transfer was very slow. That was because the link itself (not a standard Internet connection) and also because of the SSH server... I just compare it with other transfer methods using a similar device in the lab to figuring that out. It was good that I got a solution but it was not the best by far.
NetKitty to the rescue
So, I tried to do the transfer with NetKitty. Actually I first tried with Netcat as I have done many times before. It worked flawless in an interactive shell and it was way faster than the previous ssh transfer I had just described. It may be because of the lack of encryption or just because the ssh server... TBH I haven't checked the actual reason. Good news, any way... Let's write the script (yes. the transfer was part of something else). Damn... no screen, no tmux, nohup didn't worked (just I dropped a busybox there to get some extra tools including netcat). I'm not saying it wasn't possible but I couldn't find a way to launch netcat remotely using ssh and keep it in the background while returning to my shell script to actually send the file using a local netcat instance. If anybody knows how to do this I will be indeed interested. But then, I remember NetKitty has a daemon mode that I added some time ago to allow easy/temporal remote access to linux boxes. That worked fine but not when redirecting to a file.... Damn again! Fortunately for me, NetKitty is my own program and it is less than 600 LoC... it is easy to understand. What I did was to add a new flag to allow dumping data to a file and not just to the stdout. Actually I think I haven't done it the right way, and I may need to update it. Anyway, it worked fine using these commands.ssh host "/data/local/tmp/nk-arm -hub -d -os -s T,5000 -f the_file.dat" sleep 2 cat the_file.dat | nc host 5000The first command starts Netkitty in the remote machine in
hub
mode (this is the thing I probably should change :), daemon mode (-d
), one shot (-os
, the program ends when the connection is closed), and dumping everything to the file after the -f
flag.
Then I can just pipe the file using netcat or netkitty to the remote server. In the script I had to add a small delay. I observed that the ssh command was taking a bit of time to get executed after the ssh clients returns.
Other than that... now I have two more unorthodox ways to transfer files! :P
You can download Netkitty static binaries ready to use in any ARM platform from the TOOLS page.
■
CLICKS: 2864