LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 12-20-2015, 07:23 AM   #1
dorsio
Member
 
Registered: Apr 2014
Distribution: Debian
Posts: 92

Rep: Reputation: 1
Question Using Netcat command to download file from remote device


How to use Netcat command to download file (mtdblock) /dev/mtdblock3 from remote machine (which runs embedded Linux, BusyBox v1.4.2) to local computer? The remote machine and local computer are inside different private networks. Also, the local computer connected behind a NAT router.

mtd blocks

Code:
# cat /proc/mtd
dev:    size   erasesize  name
...
mtd3: 003a0000 00010000 "UBFI1"
Here's Busybox's nc implementation:

Code:
nc

    nc [OPTIONS] HOST PORT - connect nc [OPTIONS] -l -p PORT [HOST] [PORT] - listen

    Options:

            -e PROG         Run PROG after connect (must be last)
            -l              Listen mode, for inbound connects
            -n              Don't do DNS resolution
            -s ADDR         Local address
            -p PORT         Local port
            -u              UDP mode
            -v              Verbose
            -w SEC          Timeout for connects and final net reads
            -i SEC          Delay interval for lines sent
            -o FILE         Hex dump traffic
            -z              Zero-I/O mode (scanning)
 
Old 12-20-2015, 04:32 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599
Quote:
Originally Posted by dorsio View Post
How to use Netcat command to download file (mtdblock) /dev/mtdblock3 from remote machine (which runs embedded Linux, BusyBox v1.4.2) to local computer? The remote machine and local computer are inside different private networks. Also, the local computer connected behind a NAT router.
I believe the Netcat basics were handled already in your previous thread: https://www.linuxquestions.org/quest...er-4175557705/. Also you didn't include what you have tried?

If your local computer is behind a NAT router then if you can make the remote device listen you spare yourself the effort of having to set up port forwarding. For example if you can SSH into the machine and you have sufficient rights to perform this you could try 'ssh user@remote.host "dd if=/dev/mtdblock3" > /tmp/mtdblock3.dd;' which is better than using 'nc' because you probably don't want to move memory contents over the network unencrypted? If you can't then on the remote machine pipe 'dd' output through 'nc' in listening mode and then on the local machine connect to the remote machine + port and pipe to a file.
 
Old 12-20-2015, 05:48 PM   #3
dorsio
Member
 
Registered: Apr 2014
Distribution: Debian
Posts: 92

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by unSpawn View Post
I believe the Netcat basics were handled already in your previous thread: https://www.linuxquestions.org/quest...er-4175557705/. Also you didn't include what you have tried?

If your local computer is behind a NAT router then if you can make the remote device listen you spare yourself the effort of having to set up port forwarding. For example if you can SSH into the machine and you have sufficient rights to perform this you could try 'ssh user@remote.host "dd if=/dev/mtdblock3" > /tmp/mtdblock3.dd;' which is better than using 'nc' because you probably don't want to move memory contents over the network unencrypted? If you can't then on the remote machine pipe 'dd' output through 'nc' in listening mode and then on the local machine connect to the remote machine + port and pipe to a file.

The issue with netcat not solved yet. I can't download anything with netcat command due to connection timed out. SSH is not supported, only telnet. The TFTP works for small files, but failed for larger files.

should I use same command as in previous thread?
on local:
nc -l -p 5555 > UBFI1

on embedded Linux:
dd if=/dev/mtdblock3 bs=00010000 count=3a | nc 192.168.1.20 5555
 
Old 12-20-2015, 06:34 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599
Quote:
Originally Posted by dorsio View Post
I can't download anything with netcat command due to connection timed out.
It is most efficient if you tell us exactly what services can or can not be used, what commands you have tried and what errors you get in your initial post.


Quote:
Originally Posted by dorsio View Post
The TFTP works for small files, but failed for larger files.
See if busybox provides 'split' command then download each part?


Quote:
Originally Posted by dorsio View Post
should I use same command as in previous thread?
on local:
nc -l -p 5555 > UBFI1

on embedded Linux:
dd if=/dev/mtdblock3 bs=00010000 count=3a | nc 192.168.1.20 5555
That may or may not work depending on if the remote machine can reach the local machine. You talked about NAT so if you didn't set up port forwarding in your router it is unclear how this could work.
 
Old 12-21-2015, 05:40 AM   #5
dorsio
Member
 
Registered: Apr 2014
Distribution: Debian
Posts: 92

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by unSpawn View Post
It is most efficient if you tell us exactly what services can or can not be used, what commands you have tried and what errors you get in your initial post.



See if busybox provides 'split' command then download each part?



That may or may not work depending on if the remote machine can reach the local machine. You talked about NAT so if you didn't set up port forwarding in your router it is unclear how this could work.
The errors are same as in previous thread.

'Split' command not supported in busybox implementation. But 'tar' function is supported: not sure if this can help in my case.
Sure, I configured port forwarding on my router, this should not prevent connection. But I tried also without router, too.
I'm not sure about count=3a value: should be hex division calculated in HEX or Decimal units?

003a0000 00010000 = 3a (hex division)
003a0000 00010000 = 58 (decimal division)

Last edited by dorsio; 12-21-2015 at 05:48 AM.
 
Old 12-21-2015, 01:20 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599
Quote:
Originally Posted by dorsio View Post
The errors are same as in previous thread.
I only see:
Quote:
Originally Posted by dorsio View Post
Code:
nc: cannot connect to remote host (192.168.1.20): Connection timed out
so you can't reach that host. Not that weird because it's not routable over the Internet.


Quote:
Originally Posted by dorsio View Post
'Split' command not supported in busybox implementation. But 'tar' function is supported: not sure if this can help in my case.
No but if 'dd' accepts "seek" arg you can first 'dd' the device then chunk it (write 1m, seek 1m then write 1m, rinse and repeat).


Quote:
Originally Posted by dorsio View Post
But I tried also without router, too.
And? Was it any good? ;-p


Quote:
Originally Posted by dorsio View Post
I'm not sure about count=3a value: should be hex division calculated in HEX or Decimal units?
With 'dd "count" is an integer and "bs" is a string as in 1k or 1m: see 'man dd'.
 
Old 12-21-2015, 04:33 PM   #7
dorsio
Member
 
Registered: Apr 2014
Distribution: Debian
Posts: 92

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by unSpawn View Post
I only see:

so you can't reach that host. Not that weird because it's not routable over the Internet.
Will try again without router.
Quote:
Originally Posted by unSpawn View Post
No but if 'dd' accepts "seek" arg you can first 'dd' the device then chunk it (write 1m, seek 1m then write 1m, rinse and repeat).
'seek' function is not supported in BB implementation.

Quote:
Originally Posted by unSpawn View Post
With 'dd "count" is an integer and "bs" is a string as in 1k or 1m: see 'man dd'.
Not fully clear here, can you show what should be correct code in my case?
 
Old 12-21-2015, 05:23 PM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599
Quote:
Originally Posted by dorsio View Post
Will try again without router.
Won't work.


Quote:
Originally Posted by dorsio View Post
Not fully clear here, can you show what should be correct code in my case?
No, let's turn that around: you read 'man dd' then you propose what you think your command line should be, then I'll correct if necessary.
 
Old 12-22-2015, 08:39 AM   #9
dorsio
Member
 
Registered: Apr 2014
Distribution: Debian
Posts: 92

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by unSpawn View Post
Won't work.
Why? I will use external IP address. Please explain detaily.

Quote:
Originally Posted by unSpawn View Post
No, let's turn that around: you read 'man dd' then you propose what you think your command line should be, then I'll correct if necessary.
Linux DD man is vague and don't tell how to calculate count value and which unit need be 'N' blocks. Also there is no any examples of using that commands.

count=N
copy only N input blocks


This bytes in HEX format?
bs=BYTES
read and write up to BYTES bytes at a time
 
Old 12-22-2015, 09:35 AM   #10
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,661

Rep: Reputation: Disabled
To copy 3 MB. dd if=<input> of=<output> bs=1024 count=3 or dd if=<input> of=<output> bs=1M count=3
 
Old 12-22-2015, 10:13 AM   #11
dorsio
Member
 
Registered: Apr 2014
Distribution: Debian
Posts: 92

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by Emerson View Post
To copy 3 MB. dd if=<input> of=<output> bs=1024 count=3 or dd if=<input> of=<output> bs=1M count=3
In my case size is '003a0000' and erasesize (erase block size?) is '00010000'
I don't understand how to convert this correctly.
Is this correct form?
Code:
dd if=/dev/mtdblock3 bs=65536 count=58 | nc 192.168.1.20 5555

Last edited by dorsio; 12-23-2015 at 06:00 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
netcat to run remote script actmnophn Linux - Software 5 03-15-2014 09:56 PM
[SOLVED] Netcat accpeting remote connections juiceb0x Linux - Software 2 11-14-2011 03:04 PM
Fedora 13 Netcat remote connection problem bonewagon Linux - Software 2 03-07-2011 05:23 PM
How to download a file to my PC from a remote server? Atwin General 4 09-03-2008 06:37 AM
Remote download command? UltraSoul Solaris / OpenSolaris 6 04-17-2005 04:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 09:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration