From: Hendrik B. <nh...@us...> - 2010-01-27 23:14:40
|
Update of /cvsroot/arianne/unrelated-stuff/src/net/sf/arianne/tools/sfxml/download In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv17145/src/net/sf/arianne/tools/sfxml/download Added Files: DownloadXmlExport.java Log Message: initial checkin of a program intended to make backups of the forum, tracker and announcements --- NEW FILE: DownloadXmlExport.java --- /* * $Log: DownloadXmlExport.java,v $ * Revision 1.1 2010/01/27 23:14:28 nhnb * initial checkin of a program intended to make backups of the forum, tracker and announcements * */ package net.sf.arianne.tools.sfxml.download; import java.io.IOException; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; /** * downloads the project xml export from source forge * * @author hendrik */ public class DownloadXmlExport { private static final String USER_AGENT = "Hendriks Backup Program"; private String sessionCookie; /** * Posts url encoded data to the server * * @param connection HttpURLConnection * @param data url encoded data * @throws IOException in case of an input/output error */ private void post(HttpURLConnection connection, String data) throws IOException { connection.setDoOutput(true); OutputStream os = connection.getOutputStream(); os.write(data.getBytes()); os.close(); } /** * sets a custom user agent to allow SF.net to detect this progam. * * @param connection HttpURLConnection */ private void prepareConnection(HttpURLConnection connection) { connection.setRequestProperty("User-Agent", USER_AGENT); connection.setInstanceFollowRedirects(false); } private void login(String username, String password) throws IOException { URL url = new URL("https://sourceforge.net/account/login.php"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); prepareConnection(connection); post(connection, "form_loginname=" + username + "&form_pw=" + password); connection.getInputStream().close(); } /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { DownloadXmlExport downloader = new DownloadXmlExport(); // TODO: Do not read password from command line because of multi user systems downloader.login(args[0], args[1]); } } |