3

I'm connected to a device over a serial cable and using screen I have full access to the remote system.

How do I transfer an entire file(s) to my local system? Not just the contents of the file, I want the whole thing. I need to send this file as a sample to a third party so they'll want to see metadata, encoding, etc. I want to copy the file exactly as it is, the data it contains isn't really that important.

The remote system is Linux, but a proprietary box so I can't guarantee what tools it has. Local system is running Xubuntu Xenial. I can install packages onto my machine, but not the remote one. My connection is over a USB serial adaptor, so screen is connecting through a ttyUSB.

4
  • 1
    Hello Seret. 1. What do you see as "the whole thing" that isn't the contents of the file? 2. What are you running over the serial cable? For example serial TTY, SLIP, PPP. 3. What OS or Distribution are you running on the remote system, and what is "my local system" running? (Please edit your question to answer this - ideally as if you'd provided the information in the first place. Don't reply here in the comments. I can then delete my comment.) Mar 20, 2019 at 11:08
  • 1
    I assumed, based on the rs-232 in the title and "over a serial cable" in the body. if I'm wrong, I apologize, and it's easy to untag.
    – Jeff Schaller
    Mar 20, 2019 at 11:37
  • 1
    see this post, I think it's a variant of your question: unix.stackexchange.com/questions/56614/…
    – wazoox
    Mar 26, 2019 at 18:36
  • Thanks wazoox, I've given this a go, using the command: exec !! rx name-of-file and it attempted to transfer but failed with the following output: rx: ready to receive name-of-file Retry 0: Got 015 sector header then it retried several times and failed with Blocks received: 1 rx: name-of-file removed Transfer incomplete
    – Seret
    Apr 4, 2019 at 10:21

1 Answer 1

1

Seret!

Let's see if I can help. I'm thinking in your shoes, I'd look to see if the remote system has the "tar" and "base64" or "uuencode" programs installed.

If so, I'd start a fresh terminal on my workstation, start "typescript" or "script" in it - not screen for this - and then connect that to the remote server over serial. Now you are recording to a file everything you type and see on your terminal - including any output from commands you run over there. :-)

So, do like this: start a new shell and run

typescript thebigcapture.txt

a new prompt appears! Yay! Now typescript is recording everything you type in that shell and everything output for you to see. Now start your connection to that remote server and on that server :

tar -c the_file_you_want_to_xfr | base64

That's going to cause a huge, vast flood of non-sense on your screen. Do not interrupt it, don't panic! That, my friend, is your file transfer screaming across.

The tar program is making a high-fidelity archive copy of the file you want with all it's meta data and passing it through a pipe to the base64 program which is representing those data as hexidecimal numbers. Your typescript program is recording it on your local computer.

When the giant flood is done. Exit from the remote computer and then exit from screen and finally exit from typescript.

Then you edit the captured file, thebigcapture.txt, and remove from it everything above and below the base64 encoded output. Make sure you keep all the characters on the last line, which will probably be shorter than all the others.

Then you run:

base64 --decode < thebigcapture.txt > thatfile.tar

Finally, to see what you got from the other side, run:

tar tvf thatfile.tar

If you see errors from either base64 or tar about invalid input or corruption, just try again. You probably left out some of the base64 encoded data.

Once you are happy with what you have, you can gzip thatfile.tar and e-mail it to your correspondents.

Good luck! I hope you'll post your results here - I'm eager to hear how it goes!

2
  • Thanks Mike. I really like this and I did give it a go. Unfortunately there's no base64 on the target machine. I can't install it either: it's a piece of industrial equipment that isn't connected to the internet (except a GSM modem that it only uses to transmit logs)
    – Seret
    Apr 4, 2019 at 8:28
  • @Seret I'm a bit late, but you just need something to encode the binary down into the ASCII range so it'll go through a text channel. base32, base64, and uuencode are the traditional options, but there are lots of others. Industrial equipment often has xmodem or zmodem for handling firmware updates as well which could be subverted to the task.
    – Perkins
    May 12, 2021 at 22:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .