List of usage examples for org.apache.commons.net.ftp FTPClient login
public boolean login(String username, String password) throws IOException
From source file:Main.java
public static void main(String[] args) { FTPClient client = new FTPClient(); client.connect("ftp.domain.com"); client.login("admin", "secret"); String filename = "/testing/data.txt"; boolean deleted = client.deleteFile(filename); if (deleted) { System.out.println("File deleted..."); }/*from w ww .j a va 2 s .co m*/ client.logout(); client.disconnect(); }
From source file:Main.java
public static void main(String[] args) { FTPClient client = new FTPClient(); client.connect("ftp.domain.com"); client.login("admin", "secret"); String[] names = client.listNames(); for (String name : names) { System.out.println("Name = " + name); }// w ww . j a va 2 s . c o m FTPFile[] ftpFiles = client.listFiles(); for (FTPFile ftpFile : ftpFiles) { // Check if FTPFile is a regular file if (ftpFile.getType() == FTPFile.FILE_TYPE) { System.out.println("FTPFile: " + ftpFile.getName() + "; " + FileUtils.byteCountToDisplaySize(ftpFile.getSize())); } } client.logout(); client.disconnect(); }
From source file:FtpConnectDemo.java
public static void main(String[] args) { FTPClient client = new FTPClient(); client.connect("ftp.domain.com"); boolean login = client.login("admin", "secret"); if (login) {/*from www . java2s .co m*/ System.out.println("Login success..."); boolean logout = client.logout(); if (logout) { System.out.println("Logout from FTP server..."); } } else { System.out.println("Login fail..."); } client.disconnect(); }
From source file:Main.java
public static void main(String[] args) { FTPClient client = new FTPClient(); FileInputStream fis = null;//from ww w . j a v a2 s . c o m client.connect("ftp.domain.com"); client.login("admin", "secret"); String filename = "Touch.dat"; fis = new FileInputStream(filename); client.storeFile(filename, fis); client.logout(); fis.close(); }
From source file:Main.java
public static void main(String[] args) { FTPClient client = new FTPClient(); FileOutputStream fos = null;//from w ww . java 2 s.c om client.connect("ftp.domain.com"); client.login("admin", "secret"); String filename = "sitemap.xml"; fos = new FileOutputStream(filename); client.retrieveFile("/" + filename, fos); fos.close(); client.disconnect(); }
From source file:ftp_server.FileUploadDemo.java
public static void main(String[] args) { FTPClient client = new FTPClient(); FileInputStream fis = null;// w w w . ja va2 s .c o m try { client.connect("shamalmahesh.net78.net"); client.login("a9959679", "9P3IckDo"); // // Create an InputStream of the file to be uploaded // String filename = "hello.txt"; fis = new FileInputStream(filename); // // Store file to server // client.storeFile(filename, fis); client.logout(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (fis != null) { fis.close(); } client.disconnect(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.run.FtpClientExample.java
public static void main(String[] args) { FTPClient client = new FTPClient(); FileOutputStream fos = null;//from w w w . java 2 s.c o m try { client.connect(ARDroneConstants.IP_ADDRESS, ARDroneConstants.FTP_PORT); if (!client.login("anonymous", "")) System.err.println("login failed"); client.setFileType(FTP.BINARY_FILE_TYPE); String filename = "version.txt"; fos = new FileOutputStream(filename); if (!client.retrieveFile("/" + filename, fos)) System.err.println("cannot find file"); System.out.println("done"); } catch (IOException e) { e.printStackTrace(); } finally { try { if (fos != null) { fos.flush(); fos.close(); } client.disconnect(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:FTPConnect.FTPConnect.java
public static void main(String[] args) throws IOException { FTPClient ftpClient = new FTPClient(); boolean result; try {// w ww . j av a 2 s. c om // Connect to the localhost ftpClient.connect("localhost"); // login to ftp server result = ftpClient.login("admin", "password"); if (result == true) { System.out.println("Successfully logged in!"); } else { System.out.println("Login Fail!"); return; } } catch (FTPConnectionClosedException e) { e.printStackTrace(); } finally { try { ftpClient.disconnect(); } catch (FTPConnectionClosedException e) { System.out.println(e); } } }
From source file:FTPConnect.FTPBajarArchivo.java
public static void main(String[] args) throws IOException { FTPClient ftpClient = new FTPClient(); FileOutputStream fos = null;//from w w w . j a v a 2s . c om boolean result; try { // Connect to the localhost ftpClient.connect("localhost"); // login to ftp server result = ftpClient.login("", ""); if (result == true) { System.out.println("Successfully logged in!"); } else { System.out.println("Login Fail!"); return; } String fileName = "uploadfile.txt"; fos = new FileOutputStream(fileName); // Download file from the ftp server result = ftpClient.retrieveFile(fileName, fos); if (result == true) { System.out.println("File downloaded successfully !"); } else { System.out.println("File downloading failed !"); } ftpClient.logout(); } catch (FTPConnectionClosedException e) { e.printStackTrace(); } finally { try { if (fos != null) { fos.close(); } ftpClient.disconnect(); } catch (FTPConnectionClosedException e) { System.err.println(e); } } }
From source file:FTPConnect.FTPSubirArchivo.java
public static void main(String[] args) throws IOException { FTPClient ftpclient = new FTPClient(); FileInputStream fis = null;//w w w. ja v a 2s . c o m boolean result; String ftpServerAddress = "localhost"; String userName = "admin"; String password = "admin"; try { ftpclient.connect(ftpServerAddress); result = ftpclient.login(userName, password); if (result == true) { System.out.println("Logged in Successfully !"); } else { System.out.println("Login Fail!"); return; } ftpclient.setFileType(FTP.BINARY_FILE_TYPE); ftpclient.changeWorkingDirectory("/"); File file = new File("D:/File.doc"); String testName = file.getName(); fis = new FileInputStream(file); // Upload file to the ftp server result = ftpclient.storeFile(testName, fis); if (result == true) { System.out.println("File is uploaded successfully"); } else { System.out.println("File uploading failed"); } ftpclient.logout(); } catch (FTPConnectionClosedException e) { e.printStackTrace(); } finally { try { ftpclient.disconnect(); } catch (FTPConnectionClosedException e) { System.out.println(e); } } }