18

I have 2 linux computers, and a serial line between them, one of them is only accessible through a serial line that has shell on it. How can I transfer files between the 2 computers?

I've heard that it can be done with some rz/sz magic...

Can I do the same trick with a pseudo-terminal instead of other computer?

1

6 Answers 6

4

You need a terminal application like minicom. Then you connect the two computers, start minicom on one side, connect to the other side (the one where you can login) and use the sz command to send the file. Minicom will automatically detect the file transfer. Note that you might need to install the sz command on the login machine, how that is done is dependent on your distribution.

3

Copying txwikinger's answer, I would use kermit, the grandfather of file transfer programs. We used it in the 80's, long before there was Linux. Wikipedia suggests it may be better than zmodem (sz).

An alternative approach is to use SLIP or PPP, as suggested by Axel. But this howto for PPP is about 15 years old.

3

I've run into the same issue and all I had was a prompt, but no network modules loaded, no rz/sz binaries, nor anything else in the target system I could make use of in order to transfer files.

But I had echo and I found a solution where everything needed was - yes - echo.

I came across serio, a very simple, clever and open source Python script (available here: https://github.com/devttys0/serio). All this tiny gem does is to echo every single byte from the source file onto the target's shell using echo and redirecting the output to a destination file.

So, first I needed to provide a shell on target (I did it using minicom), then leave minicom and issue something like this from the host machine:

./serio.py \
-s /path/to/input/file/in/host.bin \
-d /path/to/destination/on/target.bin \
-p /dev/ttyUSB0

As stated in the project's page:

The only requirements on the embedded system is that it provides an interactive shell on the serial port, and that the shell's echo command supports the -n and -e options.

The transfer is, of course, very slow, but it will hopefully solve my issue.

Credits: I found this solution here. It points to another repository (this one: https://code.google.com/archive/p/serio/source/default/source), while I got the code from github directly and it differs slightly from the one published in that blog. Choose the one which suits best your needs. :)

1
  • The serio.py linked here is still Python 2 but somebody ported it to Python 3: github.com/matteomartelli/serio/tree/python3 And that basically works, however, one shouldn't expect to transfer larger files before the heat death of the universe... i.e., it's quite slow.
    – stefanct
    Aug 9, 2023 at 12:57
2

You could make use of the "Serial Line Internet Protocol" as described here.

Once two systems are interconnected by a slip line, you can use any IP-based tool (ftp, rcp, scp, ssh, ...) to exchange files. It probably takes too long to configure for a once-only purpose but might be worth looking at for embedded systems with RS232 port or old systems from a pre-LAN aera.

2
  • The link no longer exists. Oct 5, 2023 at 9:13
  • Thank you. The link should work now for another 10 years. Oct 5, 2023 at 13:19
1

My way of transferring a file.bin via serial connection is to use openSSL tool since I don't have other options to do base64 encoding and back:

openssl enc -base64 <file.bin > file.b64

Decode:

openssl enc -base64 -d <file.b64 > file.bin
1

first, you need a connection between host and the target.

for this example I use 2 pl2303 (connect both rx to tx and ground to ground) to connect 2 computers (host, target), this create a /dev/ttyUSB0 on both sides. Having busybox on target is possible to estabilish a connection between both.

on target you need a tty connection, you can have this on initrc or if you have a console, you can use getty directly to open an connection like this:
# sh -c 'getty -Lin -l /bin/sh 115200 /dev/ttyUSB0' &

on host you need putty to connect to target, like this:
$ putty -serial -sercfg 115200,8,n,1 /dev/ttyUSB0

to start receiving a file on target you run rx like this on putty connection:
# rx file.bz2

to start sending file on host you run sx like this:
$ sx file.bz2 < /dev/ttyUSB0 > /dev/ttyUSB0

you will see the blocks transfering, take a coffee and wait, remember this is a 115200 bauds, what its ~11 kb/s

You must log in to answer this question.

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