Sunday, November 19, 2017

FTP - FILE DOWNLOAD


import org.apache.commons.net.ftp.FTPClient;
import java.io.IOException;
import java.io.FileOutputStream;

public class Main {
  public static void main(String[] args) {
    FTPClient client = new FTPClient();
    FileOutputStream fos = null;



//ftp.dbu.edu.et is the website taken for demo
    client.connect("ftp.dbu.edu.et");
 

// username and password of ftp.dbu.edu.et
    client.login("username", "password");

    String filename = "sitemap.xml";
    fos = new FileOutputStream(filename);

    client.retrieveFile("/" + filename, fos);
    fos.close();
    client.disconnect();
  }
}

NOTE: You need FTP account with username and password.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.