Downloading and uploading files via telnet session

131,909

Solution 1

This depends which tools are installed on the client device / supported by the kernel.

Possible methods for file transfer (unordered):

  • ssh / sftp
  • encoding binary files into displayable format with base64/uuencode and then copy from/into your telnet terminal window.
  • over a simple tcp connection with netcat or socat or with bash and /dev/tcp
  • upload / download with wget or curl from a web server
  • ftp server with a command line ftp client
  • samba or nfs mount

Read Simple file transfer and How to get file to a host when all you have is a serial console? for more possibilites.


Copy desktop.jpg from the device to your pc with the netcat/nc method:

On your pc, disable temporarily (or reconfigure if possible) any firewall and run

netcat -l -p 10000 > desktop.jpg

and on the device

busybox nc A.B.C.D -p 10000 < desktop.jpg

where you need to replace A.B.C.D with the IP address of your pc. As soon as the transfer was successful, the netcat process on your pc should stop automatically. If not, something could have gone wrong and you can stop it with Ctrl+C (compare source and destination checksums to verify).

For the other direction, just exchange < and > on both sides. Make first a backup of the original desktop.jpg (cp desktop.jpg desktop_orig.jpg).

Solution 2

I have no ssh or ftp(or etc) on the device.

So, I do next:

  1. telnet a.b.c.d | tee telnet.log
  2. login and go to the file
  3. cat file.txt
  4. close session (I close tmux pane)
  5. clear telnet.log from trash

It should be easy to write utility to download/upload file over telnet

Solution 3

I just uploaded a ~7 Kb firmware file to a BusyBox based Linux embedded system over the serial port.

No networking, no file transfer utilities; no Base64 utils or anything remotely useful on the device.

On the host, I trivially encoded a firmware into the following format; a kind of hex-dump consisting of shell literals combined with printf commands:

printf "\xDE\xAD\xBE\xEF\x...\xF0"
printf "\xCA\xFE\x33\xE1\x...\xD3"

basically shell printf commands with \x escape sequences that printf interprets. On the device I did:

device $ cat > firmware.sh

then used the minicom's ASCII file send (Ctrl-AS) to send this file to the host. I could just have used copy and paste, since the amount of data is small.

Then, marked executable and ran the printf script:

device $ chmod a+x firmware.sh
device $ ./firmware.sh > firmware.bin

Checked using BusyBox's md5sum that the firmware.bin checksum on the device matches the original firmware image on the host.

P.S. The shell double quote syntax passes through \x verbatim because it's not a recognized escape sequence; hence we don't have to double up the backslashes.

Solution 4

Try with rcp command.

Use man rcp for more information in case you want to automate transfers.

By the way, you do know this is very insecure, right?

Solution 5

On your PC:

ncat -l -p 3000 > file.name

On remote device:

busybox nc -w 3 <your PC IP> 3000 < file.name

Share:
131,909

Related videos on Youtube

PRdeep Kumawat
Author by

PRdeep Kumawat

Updated on September 18, 2022

Comments

  • PRdeep Kumawat
    PRdeep Kumawat over 1 year

    I have an attendance device running Linux OS. I can connect this device via telnet session. There are some files in the device that I would like to download and upload with new files. How can I do that? I have very low knowledge on Linux OS. Would you please help!

    enter image description here

    • Admin
      Admin over 9 years
      How many files do you want to transfer? Can you paste somewhere output of busybox --help and ls -l /bin and ls -l /usr/bin, please.
    • Admin
      Admin over 9 years
      actually I wanna change desktop background of this attendance device, and want to upload our company logo there in the device. Such options is not available in device menu (I already asked for this option to vendor). So I connected it via telnet session and found desktop.jpg and other image files in the device. Now I want to get these file on My local system. and after verifying the same I will upload my desirable images in the device. So it will update device image according to my desirable images. I want to change at least desktop image which is available in the device at /mnt/mtdblock/image
    • Admin
      Admin over 9 years
      If you want to add information the next time, please edit your question instead of adding comments.
  • PRdeep Kumawat
    PRdeep Kumawat over 9 years
    I tried WinSCP utility and tried to connect the device using ftp/sftp/scp protocol. but it is not getting connected. I am able to connect the device via telnet command and able to see the files that I want to get and upload again into device.
  • YoloTats.com
    YoloTats.com over 9 years
    Probably your device does not have a ssh or ftp server running.
  • PRdeep Kumawat
    PRdeep Kumawat over 9 years
    Well I don't know that.. Is there any other way to get/upload files from that device?
  • slm
    slm over 9 years
    You can also use sz to send the files through the terminal. You'll need it on both sides.
  • YoloTats.com
    YoloTats.com over 9 years
    @PRdeepKumawat I extended the answer with an example.
  • Admin
    Admin over 5 years
    Not sure about your link in #3!
  • RalfFriedl
    RalfFriedl over 5 years
    @Goro The link in this case is not an explanation that can be quoted, it is an online tool that is essential for the answer. It would be better to have a local program for that task.
  • Igor Zelaya
    Igor Zelaya over 5 years
    Thanks @RalfFriedl. I edited my answer for clarification.
  • Alexandre Schmidt
    Alexandre Schmidt almost 3 years
    On the device side, I had to remove -p from the command line for it to work: busybox nc A.B.C.D 10000 < desktop.jpg.