Skip to content

Instantly share code, notes, and snippets.

@speters33w
Created September 19, 2022 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save speters33w/a34ef2a302b8e0383f30faf824688231 to your computer and use it in GitHub Desktop.
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
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();
}
}
:: 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