File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Sockets and Internet Protocols and the fly likes Download a file via https Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Download a file via https" Watch "Download a file via https" New topic

Download a file via https

Maky Chopra
Ranch Hand

Joined: Apr 11, 2001
Posts: 149
Need some help here.. I need to run a program from the prompt (with a crontab) say, $java
Now, download.cgi will display the myfile.txt link if you have logged in..
I have the following program that can download a file (and display it in an applet) :
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class GetFile {
public static void main(String[] arguments) {
if (arguments.length == 1) {
PageFrame page = new PageFrame(arguments[0]);;
} else
System.out.println("Usage: java GetFile url");
class PageFrame extends JFrame {
JTextArea box = new JTextArea("Getting data ...");
URL page;
public PageFrame(String address) {
setSize(600, 300);
JScrollPane pane = new JScrollPane(box);
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
try {
page = new URL(address);
} catch (MalformedURLException e) {
System.out.println("Bad URL: " + address);
void getData(URL url) {
URLConnection conn = null;
InputStreamReader in;
BufferedReader data;
String line;
StringBuffer buf = new StringBuffer();
try {
conn =;
box.setText("Connection opened ...");
in = new InputStreamReader(conn.getInputStream());
data = new BufferedReader(in);
box.setText("Reading data ...");
while ((line = data.readLine()) != null)
buf.append(line + "\n");
} catch (IOException e) {
System.out.println("IO Error:" + e.getMessage());
I need some help to
1. Handle https protocol using jsse
2. Download to a ascii file instead of a applet &
3. handle the login to this cgi script.

Thanks for the earlier help.. I was able to get this far with that !
I agree. Here's the link:
subject: Download a file via https
jQuery in Action, 3rd edition