Comment télécharger un fichier depuis un script, peu importe l'OS ?
0x01. OUTILS
cURL
curl "http://site.com/folder/file.zip" -o "/path/to/file.zip"
WGet
wget "http://site.com/folder/file.zip" -O "/path/to/file.zip"
lynx
lynx -dump "http://site.com/folder/file.zip" > "/path/to/file.zip"
fetch
fetch "http://site.com/folder/file.zip" > "/path/to/file.zip"
netcat
echo "/folder/file.zip HTTP/1.1" | nc site.com 80 > "/path/to/file.zip"
0x02. SCRIPTS
Python
#!/usr/bin/python import urllib2 URL = "http://site.com/folder/file.zip" OUTFILE = "/path/to/file.zip" buffer = urllib2.urlopen(URL).read() open( OUTFILE , "wb" ).write(buffer)
Perl
#!/usr/bin/perl use strict; use warnings; use LWP::Simple; my $URL = "http://site.com/folder/file.zip"; my $OUTFILE = "/path/to/file.zip"; getstore($URL, $OUTFILE);
Ruby
require 'net/http' $URLHOST = "site.com" $URLPATH = "/folder/file.zip" $OUTFILE = "/path/to/file.zip" Net::HTTP.start( $URLHOST ) do |http| resp = http.get( $URLPATH ) open( $OUTFILE , "wb") do |file| file.write(resp.body) end end
Powershell
$storageDir = $pwd $webclient = New-Object System.Net.WebClient $URL = "http://site.com/folder/file.zip" $OUTFILE = "c:/path/to/file.zip" $webclient.DownloadFile($URL,$OUTFILE)
=> Écrit par : Nicolas, le 12 octobre 2017