Created
September 19, 2022 00:46
-
-
Save speters33w/a34ef2a302b8e0383f30faf824688231 to your computer and use it in GitHub Desktop.
wget replacement, allows command line download using curl with the format: download https://central.github.com/setup.msi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.FileWriter; | |
import java.io.IOException; | |
/** | |
* Creates a temporary batch file to run curl to download files. | |
* uses the url from args for the command. | |
* This file must be compiled in a class (c:\batch\CurlDownload.class) | |
* to work with the download.bat file. | |
*/ | |
public class CurlDownload { | |
public static void main(String[] args) throws IOException{ | |
//get the url from args | |
String url = args[0]; | |
//strip the file name from the url | |
String fileName = args[0].substring(args[0].lastIndexOf("/")+1); | |
//create the temporary batch file | |
FileWriter myWriter = new FileWriter("tempcurl.bat"); | |
// downloads to c:\download, this can be changed | |
// or even modified with JFileChooser.showSaveDialog | |
myWriter.write("@echo off\ncurl " | |
+ url + " --output c:\\download\\" | |
+ fileName + "\ncd c:\\download\n"); | |
myWriter.close(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: A very simple batch file that works with Java and curl | |
:: to download files with curl using a command similar to: | |
:: download https://curl.se/windows/dl-7.85.0_2/curl-7.85.0_2-win64-mingw.zip | |
:: Assumes this batch file and the compiled CurlDownload.class are in | |
:: c:\batch , c:\batch is in the path environment variable | |
:: and you are downloading to c:\download | |
@echo off | |
cd c:\batch | |
java CurlDownload %1 | |
tempcurl.bat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment