Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Is there any way to send a file (picture or video) using Netcat and UDP. It defaults as TCP, but I would like to send using UDP. I tried simply adding -u to the nc command, but that didn't work. Here are the two commands I'm using:

cat File.jpg | nc -u -l 777
nc -u 192.168.x.x 777 | pv -b > newfile.jpg

I used my IP address for x.x, and the corresponding file on my PC. I am also using Ubuntu.

Thanks for any assistance!

share|improve this question
    
@Oliver: This is exactly the kind of answer that is of no practical use. I understand the point you try to make, but Mulaz gave the commands that were asked about. Whether or when to use TCP/UDP is the requester's decision, not the point of this post. –  user140304 Oct 10 '12 at 17:15

2 Answers 2

Try it like this:

nc -u -l 7777 > newfile.jpg #on the destination machine
cat file.jpg | nc -u 192.168.x.x 7777 #on the source machine

Usually you want the machine getting the file to "listen" (run that first), and when it's listening, send the data over udp. UDP does not have a 'handshake' sequence, and packets are sent immediately, even if noone is listening*.

*sometimes you get an ICMP packet, that the port is closed (unreachable), but you cannot depend on that (firewalls etc.)

share|improve this answer
4  
Just to say it explicitly: UDP has absolutely no "reliability, ordering, or data integrity. Thus, UDP provides an unreliable service and datagrams may arrive out of order, appear duplicated, or go missing without notice. UDP assumes that error checking and correction is either not necessary or performed in the application, avoiding the overhead of such processing at the network interface level." (Wikipedia) –  wfaulk May 6 '12 at 2:37

I think this question must be answered as follows: Yes, there is a way of sending a file with Netcat over UDP. However, it is not possible to reliably receive this file on the destination host.

If you want to have a usable file on the destination host, look for another solution.

share|improve this answer
    
The file will be recieved correctly 99+% of the time. Packet error/loss rates on a local network are very low. I know JPEG is a bad example, but sometimes, with some data, you don't need 100%, especially if you send it often (sensors, etc.). –  mulaz May 6 '12 at 14:09
    
The question was not about a local network, nor about lossy data. It was about a normal file for which netcat and udp is not the way to go. –  Oliver May 7 '12 at 5:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.