Most of the time we are trying to transfer file over network and stumble upon the problem which tool to use. There are again numerous methods available like FTP, SCP, SMB etc. But is it really worth the effort to install and configure such complicated software and create a sever at your machine when you only need to transfer one file and only once.
Suppose you want to transfer a file “file.txt” from A to B
Anyone can be server or client, lets make A as server and B as client.
$ nc -l 1567 < file.txt
$ nc -n 172.31.100.7 1567 > file.txt
Here we have created a server at A at redirected the netcat input from file file.txt, So when any connection is successfull the netcat send the content of the file.
Again at the client we have redirect the output of netcat to file.txt. When B connects to A , A sends the file content and B save that content to file file.txt.
It is not necessary do create the source of file as server we can work in the eopposeit order also. Like in the below case we are sending file from B to A but server is created at A. This time we only need to redirect ouput of netcat at to file and input at B from file.
B as server (Server)
$ nc -l 1567 > file.txt
$ nc 172.31.100.23 1567 < file.txt