• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Download a file via https

 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Need some help here.. I need to run a program from the prompt (with a crontab) say, $java https://www.mcard.com/cgi-ssl/download.cgi/myfile.txt
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.*;
import java.net.*;
import java.io.*;
public class GetFile {
public static void main(String[] arguments) {
if (arguments.length == 1) {
PageFrame page = new PageFrame(arguments[0]);
page.show();
} else
System.out.println("Usage: java GetFile url");
}
}
class PageFrame extends JFrame {
JTextArea box = new JTextArea("Getting data ...");
URL page;
public PageFrame(String address) {
super(address);
setSize(600, 300);
JScrollPane pane = new JScrollPane(box);
getContentPane().add(pane);
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
System.exit(0);
}
};
addWindowListener(l);
try {
page = new URL(address);
getData(page);
} 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 = this.page.openConnection();
conn.connect();
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");
box.setText(buf.toString());
} 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 !
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic