Search code examples
powershellfile-uploadnetcat

How to make netcat server to handle upload file from Powershell?


I'm trying to upload files from a powershell script to a netcat server.

In order to retrieve the files I use the command

nc -lvp 80 > /tmp/temp.txt

on my linux machine.

In order to start the upload from my windows 10, I use the following function with powershell:

function upload($path){
    $uri = "http://ip_adress"
    $wc = New-Object System.Net.WebClient
    $res = $wc.UploadFile($uri, $path)
}

The first uploaded file is received but the powershell script ends with a timeout and once the timeout is raised, the netcat server close. Netcat is not able to return a 200 response to the powershell in order to confirm the end of the upload.

Is there any option in order to make netcat to "survive" and keep on receiving files ?

I tried to handle tiemout error on Powershell but it does not avoid netcat to end.


Solution

  • Netcat cannot return 200 response because it is not a HTTP server. It is almost like a simple cat command, only done over the network. Some server (SSH, FTP, SFTP) needs to be running on the Linux side to accept the files. Then something like PowerShell Remoting Over SSH can be used to transfer files.