Establish ftp connection
import java.io.IOException; import sun.net.ftp.FtpClient; public class FtpConnectionDemo { public static int BUFFER_SIZE = 10240; private FtpClient m_client; private String host = ""; private String user = ""; private String password = ""; private String sDir = ""; public FtpConnectionDemo() { try { System.out.println("Connecting to host " + host); m_client = new FtpClient(host); m_client.login(user, password); System.out.println("User " + user + " login OK"); System.out.println(m_client.welcomeMsg); m_client.cd(sDir); System.out.println("Directory: " + sDir); m_client.binary(); System.out.println("Success."); } catch (Exception ex) { System.out.println("Error: " + ex.toString()); } } protected void disconnect() { if (m_client != null) { try { m_client.closeServer(); } catch (IOException ex) { } m_client = null; } } }