Advertisement
raffaele181188

Java FTP Client Apache Commons Net

Aug 15th, 2012
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. package com.zybnet;
  2.  
  3. import java.io.IOException;
  4. import java.io.OutputStream;
  5. import java.net.SocketException;
  6.  
  7. import org.apache.commons.io.output.CountingOutputStream;
  8. import org.apache.commons.io.output.NullOutputStream;
  9. import org.apache.commons.net.ftp.FTPClient;
  10.  
  11. public class FTP {
  12.    
  13.     public static void main(String[] args) throws SocketException, IOException {
  14.         FTPClient client = new FTPClient();
  15.         client.connect("ftp.mozilla.org");
  16.         client.login("anonymous", "");
  17.         client.enterLocalPassiveMode();
  18.        
  19.         OutputStream out = new CountingOutputStream(new NullOutputStream()) {
  20.             @Override
  21.             public void beforeWrite(int count) {
  22.                 super.beforeWrite(count);
  23.                 System.out.println("Downloaded " + getCount() + " bytes");
  24.             }
  25.         };
  26.        
  27.         for (String filename: new String[] {"MD5SUMS", "SHA1SUMS"})
  28.             client.retrieveFile("pub/firefox/releases/15.0b4/" + filename, out);
  29.        
  30.         out.close();
  31.         client.disconnect();
  32.     }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement