I create a
.zip file with WinRAR on my Windows, it can be opened and extracted on Linux as well as Windows if I transfer it via mail or any other common way.
But when I transfer it via Netcat, the zip file gets damaged.
On Linux, when I try to extract the netcatted file with
7z, I get errors like:
Open ERROR: Can not open the file as [zip] archive WARNINGS: Headers Error: There are data after the end of archive
I move that same netcatted zip file back to windows and try to open it, I get error:
The archive is either in unknown format or damaged.
The zip file in question contains a folder, which contains files.
My linux machine is the listener, I used this netcat solution: HERE
I thought that may have been the problem, so I just used the basic solution:
nc -lp PORT > file.zip
Sender (Windows, PowerShell):
Get-Content ZIP_FILE | ./Netcat32 IP PORT
Still wouldn't work.
Note that I had no problem transferring text files, just zip files.
Below is the comparison of the same 2 zip files, the left one is transferred via netcat (can't be opened by either Linux or Windows), the right one is via mail (can be opened by both). They were opened in
What am I doing wrong and how to make it work?
EDIT: According to Kamil Maciorowski I've tried to send the zip file through netcat as an stream of bytes, using this code in Powershell, Windows:
#Sender: $contents=Get-Content -Encoding Byte -ReadCount 0 ./file.zip echo $contents | ./NetCat32 IP PORT
Now on the linux machine I have a zip file that is 6 times the original size (which is no problem), and its contents are 1-3 digit numbers in each newline. (But shouldn't they all be in 1 line because I used the -ReadCount 0 tag? (see -ReadCount HERE)
I cannot open that file. Trying to extract it I get an error: "Is not an archive".
Typing the linux command file to see the file type of "file.zip" I get: "ASCII TEXT, with CRLF line terminators"
I booted another linux (as client), tried transfering the SAME problematic zip file that has been originally created on windows, and it worked without problems.
I booted back into windows and tried the following commands in cmd.exe:
type file.zip | Netcat32.exe IP PORT Netcat32.exe IP PORT < file.zip
I tried the same on powershell. I even tried using
get-content with all the available encoding types (unknown, utf8, unicode...). No success.
It seems that the problem is in powershell and its own
cat command synonyms (
gc, get-content, type, cat)..
OK, I have to run the command via cmd.exe, but I wish to run the cmd.exe command inside powershell if possible.
My current solution that works is to have a .bat file with the whole command, which is called inside of powershell... But I'd be glad to have a cleaner option.
No need for a .bat file... I had problems with
invoke-command, invoke-expression, start-job... but this command worked successfuly:
Start-Process cmd -ArgumentList " /c type file.zip | Netcat32.exe IP PORT"
Problem was in the way the Powershell
Get-Content command works, so I had to use solutions in cmd.exe
I will wait 1-2 days for a powershell solution before I answer the question.