I wrote this script to send a file using netcat. My intention is to open the netcat port in the destination server from the origin, this way I do everything with just one script instead of having one on the dest and one on the source.
#!/bin/bash
FILE=$1
SERVDEST=$2
SIZE=`du -h --apparent-size $FILE | cut -f1`
DATE=`date +%Y%m%d%H%M`
echo "Sending file $FILE of $SIZE to $SERVDEST" >> NCtransf_$DATE.log
echo "" >> NCtransf_$DATE.log
ssh $SERVDEST "nc -l 6969 > /backup/backupSO/nc_$FILE.tgz" &
#sleep 5 #tried sleeping for some secs but it didn't work either
(/usr/bin/time --format='Transfer took %e seconds' tar czf - $FILE | nc $SERVDEST 6969) &>> NCtransf_$DATE.log
echo "" >> NCtransf_$DATE.log
For some reason the file is created in the destination but its size is 0. The information never goes through and the netcat port stays open on the other side. I also tried changing this line ssh $SERVDEST "nc -l 6969 > /backup/backupSO/nc_$FILE.tgz" &
for this ssh $SERVDEST "nohup nc -l 6969 > /backup/backupSO/nc_$FILE.tgz" &
but same results happened.
If I try the same lines separated (opening the port manually on the destination) it works like a charm. Just for the record I have passwordless ssh connection and the port is open in the firewall.