com
com

Reputation: 2704

Socket left in TIME_WAIT after file transfer via netcat

Using Copying by NetCat I am trying to copy files throught network by NetCat. From console it work pretty well. First I run listening netcat on the destination machine and after I run sending on source machine.

The problem is it's doen't work from script from the source machine:

ssh -f user@$desthost 'nc -l 1234 | tar xvf - > /dev/null &' #listening on destination host

tar cv /tmp/file | nc $desthost 1234 #sending to destination host

I saw that after running port 1234 is still was open and status of the socket was TIME_WAIT.

If you know what's the problem, please, help me out.

And by the way, after copying how can I validate that the content is identical?

Thanks!

Addendum:

I found one very strange thing, the same implementation with screen on destination work works, but not stable, sometimes it doesn't copy a file.

ssh user@$desthost screen -dm -S test 'nc -l 1234 | tar xvf - ' #listening on destination host

Maybe there is an issue with timeout?

Upvotes: 1

Views: 1096

Answers (1)

barsju
barsju

Reputation: 4446

You don't need netcat for that: http://www.cyberciti.biz/faq/howto-use-tar-command-through-network-over-ssh-session/

You just need a single ssh connection.

Afterwards use md5sum to compare the files. It's smart to also check the filesize first..

Upvotes: 1

Related Questions