0
1 machine listens(linux), while multiple clients(windows) send files to it on one and the same listening port. Netcat receives the files serially with the -k tag.
Listening machine:
nc -lp PORT -k > fileX
Clients:
nc IP PORT < file??
What I want is to receive multiple files from multiple sources WITHOUT them overwriting each other.
Please look at the previous commands. The listener machine with always write output to fileX, thus overwriting the previous client's file.
I want to somehow be able to change the output filename for every different client. Can the client send the string "file10" over netcat somehow and so tell the listener to output to > file10 ?
Thank you.
EDIT: Came up with an idea:
This is automated via script:
Firstly, listener sets output file to file.txt. (nc -lp PORT > file.txt)
Client sends string (eg "file123") via netcat. (This will be the filename for the file that will be sent in the future.)
Listener writes to file.txt, then reads file.txt, and starts a new netcat listener with output file > file123
Finally, client sends data.
Nice. How do I send the file if the client is windows? I tried in powershell.. This is how far I got. $file=Get-Content ./somefile; echo "filename10"$file | ./Netcat32 IP PORT. On the linux machine i get a file called " 'filename10'$'\r' " (without double quotes). The file contents are correct but the file name is off. – MyWays – 2018-10-21T19:08:23.160
@MyWays I cannot help you with this PowerShell code (I'm a Linux guy, I have never worked with PowerShell), but the issue looks like being caused by different line endings in Windows and in Unix.
– Kamil Maciorowski – 2018-10-21T19:12:48.153@MyWays Although proper code between
read
andcat
in Linux can fix this. Give me few minutes. – Kamil Maciorowski – 2018-10-21T19:15:09.793@MyWays My answer now addresses this. – Kamil Maciorowski – 2018-10-21T19:30:52.180
this is some wizardry right here. – MyWays – 2018-10-21T19:32:12.417
Sorry to hijack, since there's no PM option on this forum apparently.. but how to close the connection on the client after the file is done transferring? I got netcat version 1.11 on windows that has no -q parameter like nc does on linux. – MyWays – 2018-10-21T19:40:27.773
Let us continue this discussion in chat.
– Kamil Maciorowski – 2018-10-21T19:41:28.783