List of usage examples for org.apache.commons.net.ftp FTPClient login
public boolean login(String username, String password) throws IOException
From source file:gui.TesteHackathon.java
public static void enviaImagem() { String server = "www.ejec.co"; int port = 21; String user = "ejec"; String pass = "cPanel2015"; FTPClient ftpClient = new FTPClient(); try {/* w w w. j a v a 2 s . co m*/ ftpClient.connect(server, port); ftpClient.login(user, pass); ftpClient.enterLocalPassiveMode(); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); // APPROACH #1: uploads first file using an InputStream File firstLocalFile = new File("image.jpg"); String firstRemoteFile = "public_html/virtualfit/image.jpg"; InputStream inputStream = new FileInputStream(firstLocalFile); System.out.println("Start uploading first file"); boolean done = ftpClient.storeFile(firstRemoteFile, inputStream); inputStream.close(); if (done) { System.out.println("The first file is uploaded successfully."); } } catch (IOException ex) { System.out.println("Error: " + ex.getMessage()); ex.printStackTrace(); } finally { try { if (ftpClient.isConnected()) { ftpClient.logout(); ftpClient.disconnect(); } } catch (IOException ex) { ex.printStackTrace(); } } }
From source file:CFDI_Verification.CFDI_Verification.java
public static String test_Connection(String directory) { String server = "192.1.1.64"; String user = "ftpuser"; String pass = "Oracle123"; String result = "No Connected!"; FTPClient ftpClient = new FTPClient(); try {// w w w . j a va2 s . co m ftpClient.connect(server); ftpClient.login(user, pass); ftpClient.enterLocalPassiveMode(); ftpClient.changeWorkingDirectory(directory); if (ftpClient.isConnected() == true) { result = "Connected to " + ftpClient.printWorkingDirectory(); } ftpClient.logout(); ftpClient.disconnect(); } catch (IOException ex) { System.out.println("Ooops! Error en conexin." + ex.getMessage()); } finally { return result; } }
From source file:CFDI_Verification.CFDI_Verification.java
public static void list_directories(String directory) { String server = "192.1.1.64"; String user = "ftpuser"; String pass = "Oracle123"; String result = "No Connected!"; FTPClient ftpClient = new FTPClient(); try {/* ww w. j a va 2 s . c o m*/ ftpClient.connect(server); ftpClient.login(user, pass); ftpClient.enterLocalPassiveMode(); ftpClient.changeWorkingDirectory(directory); String[] directories = ftpClient.listNames(); String dir; for (int i = 0; i < directories.length; i++) { System.out.println(directories[i]); dir = directories[i]; } ftpClient.logout(); ftpClient.disconnect(); } catch (IOException ex) { System.out.println("Ooops! Error en conexin." + ex.getMessage()); } }
From source file:CFDI_Verification.CFDI_Verification.java
public static ARRAY getDirectories(String directory) throws SQLException { Connection conn = new OracleDriver().defaultConnection(); ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor("DIRECTORIES_LIST", conn); String server = "192.1.1.64"; String user = "ftpuser"; String pass = "Oracle123"; String result = "No Connected!"; FTPClient ftpClient = new FTPClient(); try {/*from w w w . j av a 2s . c om*/ ftpClient.connect(server); ftpClient.login(user, pass); ftpClient.enterLocalPassiveMode(); ftpClient.changeWorkingDirectory(directory); String[] directories = ftpClient.listNames(); ARRAY directories_list = new ARRAY(descriptor, conn, directories); ftpClient.logout(); ftpClient.disconnect(); return directories_list; } catch (IOException ex) { System.out.println("Ooops! Error en conexin." + ex.getMessage()); } return null; }
From source file:ftp.FTPtask.java
/** * ? ? ? ?? Folder/* w w w .j a v a 2 s .c o m*/ * @param FTPADDR, ? ? * @param user, * @param password, * @param Folder, ?? ? * @return String[] result, ?? / */ public static String[] GetList(String FTPADDR, String user, String password, String Folder) { String[] result; result = null; FTPClient client = new FTPClient(); try { client.connect(FTPADDR); client.login(user, password); client.changeWorkingDirectory(Folder); result = client.listNames(); client.logout(); } catch (IOException e) { e.printStackTrace(); } finally { try { client.disconnect(); } catch (IOException e) { e.printStackTrace(); } } return result; }
From source file:com.clothcat.hpoolauto.HtmlUploader.java
/** * Upload the html via FTP/* www . j ava 2s.c o m*/ */ public static void uploadHtml() { FTPClient ftpc = new FTPClient(); FTPClientConfig conf = new FTPClientConfig(); ftpc.configure(conf); try { ftpc.connect(Constants.FTP_HOSTNAME); ftpc.login(Constants.FTP_USERNAME, Constants.FTP_PASSWORD); File dir = new File(Constants.HTML_FILEPATH); File[] files = dir.listFiles(); ftpc.changeWorkingDirectory("/htdocs"); for (File f : files) { HLogger.log(Level.FINEST, "Uploading file: " + f.getName()); FileInputStream fis = new FileInputStream(f); ftpc.storeFile(f.getName(), fis); } ftpc.logout(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { if (ftpc.isConnected()) { try { ftpc.disconnect(); } catch (IOException ioe) { } } } }
From source file:com.qasp.diego.arsp.Atualiza.java
public static boolean DownloadFTP() throws IOException { final String FTPURL = "37.187.45.24"; final String USUARIO = "diego"; final String SENHA = "Jogador5"; final String ARQUIVO = "data.dat"; FTPClient ftp = new FTPClient(); try {/* w w w . j ava 2 s . com*/ ftp.connect(FTPURL); ftp.login(USUARIO, SENHA); ftp.changeWorkingDirectory("/httpdocs/tcc/TCCpython"); ftp.setFileType(FTP.BINARY_FILE_TYPE); ftp.enterLocalPassiveMode(); OutputStream outputStream = null; boolean downloadcomsucesso = false; try { File f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), ARQUIVO); f.createNewFile(); outputStream = new BufferedOutputStream(new FileOutputStream(f)); downloadcomsucesso = ftp.retrieveFile(ARQUIVO, outputStream); } finally { if (outputStream != null) outputStream.close(); } return downloadcomsucesso; } finally { if (ftp != null) { ftp.logout(); ftp.disconnect(); } } }
From source file:ftp.FTPtask.java
/** * Change directory//from ww w . j a v a 2 s .co m * @param FTPADDR, ? ? * @param user, * @param password, * @param ChangeFolder, , , /upload */ public static void FTPChangeDir(String FTPADDR, String user, String password, String ChangeFolder) { FTPClient client = new FTPClient(); try { client.connect(FTPADDR); client.login(user, password); int replyCode = client.getReplyCode(); if (!FTPReply.isPositiveCompletion(replyCode)) { System.out.println("Connect failed"); return; } boolean success = client.login(user, password); showServerReply(client); if (!success) { System.out.println("Could not login to the server"); return; } // Changes working directory success = client.changeWorkingDirectory(ChangeFolder); showServerReply(client); if (success) { System.out.println("Successfully changed working directory."); } else { System.out.println("Failed to change working directory. See server's reply."); } // logs out client.logout(); client.disconnect(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:ftp.FTPtask.java
/** * Upload a file to a FTP server//from w w w . j av a 2 s. c om * @param FTPADDR, ? ? * @param user, * @param password, * @param PathOnFtp, - /upload/touch.dat * @param FilenameOnLocalMachine, - C:/somefile.txt */ public static void UploadFileOnFtp(String FTPADDR, String user, String password, String PathOnFtp, String FilenameOnLocalMachine) { FTPClient client = new FTPClient(); FileInputStream fis = null; try { client.connect(FTPADDR); client.login(user, password); // Create an InputStream of the file to be uploaded String filename = FilenameOnLocalMachine; fis = new FileInputStream(filename); // Store file to server client.storeFile(PathOnFtp, 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:ftp.FTPtask.java
/** * Download File from FTP/* ww w. j a v a2 s .c om*/ * @param FTPADDR, ? ? * @param user, * @param password, * @param FullPathToPutFile - , ?? * @param FilenameOnFTP - ? (? /upload/) */ public static void DownloadFileFromFTP(String FTPADDR, String user, String password, String FullPathToPutFile, String FilenameOnFTP) { FTPClient client = new FTPClient(); FileOutputStream fos = null; try { client.connect(FTPADDR); client.login(user, password); // The remote filename to be downloaded. String filename = FullPathToPutFile; fos = new FileOutputStream(filename); // Download file from FTP server client.retrieveFile("/upload/" + FilenameOnFTP, fos); // } catch (IOException e) { e.printStackTrace(); } finally { try { if (fos != null) { fos.close(); } client.disconnect(); } catch (IOException e) { e.printStackTrace(); } } }