$ cat file | nc host.example.com 8888
I don't think a dedicated utility is required.
Edit: Sorry about my comment coming off as a bit hostile, I did not intend it to be.
$ cat file | nc host.example.com 8888
I don't think a dedicated utility is required.
Edit: Sorry about my comment coming off as a bit hostile, I did not intend it to be.
But that's not the point here. Sometimes you just got to make something because you want to, because it fits a specific need that maybe not a lot of other people have, or because it's a learning experience, or just for the heck of it. So, no, it's not required, but that doesn't mean it's useless.
It's cool that the author did something productive that works for him/her, and it's even cooler they shared it with everyone.
I can say that's already infinitely more than what I made today. How about you?
I dont begrudge people reinventing the wheel, but i fully suspect this wouldn't have been written if the author knew about nc.
I appreciate the criticism though, it is always good to question the investment of time. In this case, I feel comfortable with it. Can't discount the joy of programming little things either.
hostname can be a numerical IP address or a symbolic hostname (unless the
-n option is given). In general, a hostname must be specified, unless
the -l option is given (in which case the local host is used).I'm not saying that it's such a big hassle that we need complicated ways of avoiding it, but this is definitely a cool project that does a away with a (minor) pain point and I for one applaud the author for scratching his itches and sharing with the world, even if his hack isn't perfect.
Recipient listens on 0.0.0.0:
recipient$ nc -l 0.0.0.0 6969 > file
Sender broadcasts to broadcast address: sender$ <file | nc 192.168.0.255 6969
or sender$ <file | nc 255.255.255.255 69692. A very minor point, but you are still required to know (or at least specify) a the filename on the receiving end. My solution does not.
sender$ tar -c file | nc -l 12345
recipient$ nc addr 12345 | tar -x
This will create a file on the recipient side with the specified name and properties (and you run the sender command first)sender$ tar -c awesome.jpg | nc -l 0.0.0.0 12345
(waiting forever)
recipient$ nc 255.255.255.255 12345 | tar -x
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
(Having spent years doing minor little things that nobody ever would care to hear about (back in the day) I can of course fully understand the positive aspects of the mental process. You learn something and perhaps people leave comments that make you feel good which spurs you on to do better things.)
Some people voted it up, I can't control that. I really could care less about karma, in fact, the critical comments (except yours) have been very useful and worth the post.
I am just being part of a community.
I now see though that ncp (http://www.fefe.de/ncp/) would have probably sufficed, though it is a slightly different approach.
Sorry if you feel mislead.
hostname can be a numerical IP address or a symbolic hostname (unless the
-n option is given). In general, a hostname must be specified, unless
the -l option is given (in which case the local host is used). char filename[MAXNAMELEN];
and then a few lines down... filename_size = 0;
memcpy(&filename_size, buf, sizeof(int));
memcpy(filename, &buf[sizeof(int)], filename_size);
Oops! Looks like both the client and the server have to be trusted, otherwise we've got at least one probably-exploitable vulnerability. And there's no mechanism for authentication, so it's really only safe to use on locally-secured network. (That took about 40 seconds to find, by the way - I would not be particularly suprised if there were more subtly lurking issues.)I sympathize with the sentiment of "people should go out and try to create things themselves, even at the risk of failing" (or "especially" at the risk of failing), but from any objective standpoint, bcp isn't a good program. 400 lines of C to badly accomplish what 2 lines of shell can do? Someone else commented about it being very much in the unix spirit - no, I don't really think so. netcat + openssl would be in the unix spirit.
Not meant to be a criticism of the author - it's a cool project, if you don't care about certain "real-world" concerns (which isn't as unreasonable as it sounds).
I should have noted somewhere, this isn't ready for production by any means, just a first iteration of an idea I had. It is currently intended to be used on a trusted network.
Thanks for pointing this out though.
$ <file nc host.example.com 8888
(performance benefits more apparent with larger files) $ cat foo | bar
ends up creating two processes and a pipe. The foo file is first read by cat and then written onto the pipe (which bar then reads). $ <foo bar
is an input redirection: foo is opened for reading and bar's standard input fd is set to that open file (so the file's data is only read once)But for the usual case where it is I/O-constrained, you can often get files across more quickly by throwing CPU at reducing the total amount of bandwidth required by, e.g., using something like bzip or pbzip:
pbzip2 < file | nc $host $port
And on the other side: nc -l $port | pbzip2 -d > fileEdit: Just to be clear, that'd be:
$ nc -l $port | gzip -d > $filename
$ cat $filename | gzip | nc $host $portIf you massage the discovery/rendezvous part in, it won't be nearly as simple as a single 'nc' command.
nc -l 8888 | tar xf - tar cf - file | nc host.example.com 8888
Also, unnecessary process spawned with cat: nc.host.example.com 8888 < file