M
M
mikserok2015-10-08 11:24:11
linux
mikserok, 2015-10-08 11:24:11

How to download a file with NCat like Wget?

I got a built-in Linux system without WGET and CURL, there is only NCat.
You need to write a one-liner to download a file ( pastebin.com/raw.php?i=kqqfkeDg) via http protocol, so that you can then insert it into a shell script.
Works in interactive mode

[email protected]:~# ncat pastebin.com 80 
GET /raw.php?i=kqqfkeDg HTTP/1.1
Host: pastebin.com
User-Agent: Mozilla/5.0

HTTP/1.1 200 OK
....

But the one-liner receives 0 bytes in response
[email protected]:~# echo -e "GET /raw.php?i=kqqfkeDg HTTP/1.1\nHost: pastebin.com\nUser-Agent: Mozilla/5.0\n\n" | ncat pastebin.com 80 -v
Ncat: Version 6.49BETA4 ( http://nmap.org/ncat )
Ncat: Connected to 190.93.243.15:80.
Ncat: 78 bytes sent, 0 bytes received in 0.29 seconds.

Where did I go wrong and how is it correct?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
asd111, 2015-10-08
@asd111

instead \nof\r\n

V
Vlad Zhivotnev, 2015-10-08
@inkvizitor68sl

and there is no GET binary either?
Actually, it looks like cloudflare banned you. So the command is correct. Try to remove UA.

J
jcmvbkbc, 2015-10-08
@jcmvbkbc

cat <<EOF > rq
GET /raw.php?i=kqqfkeDg HTTP/1.1
Host: pastebin.com
User-Agent: Mozilla/5.0

EOF
tail -n +0 -f rq | ncat pastebin.com 80

In your version, echo terminates and stdin falls off at nc, which causes it to terminate too.
In the proposed version, stdin is not closed, as in interactive use, but you need to somehow ensure that the file is received completely and terminate nc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question