List of usage examples for org.apache.commons.net.ftp FTPClient FTPClient
public FTPClient()
From source file:com.clothcat.hpoolauto.HtmlUploader.java
/** * Upload the html via FTP//from w ww . j a v a2 s . com */ 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:jm.web.Ftp.java
public boolean conectar(String servidor, int puerto, String usuario, String clave) { try {/*from w w w . jav a 2 s.c o m*/ this.ftp = new FTPClient(); //ftp.connect(servidor); ftp.connect(servidor, puerto); boolean login = ftp.login(usuario, clave); int reply = this.ftp.getReplyCode(); if (FTPReply.isPositiveCompletion(reply)) { this.ftp.setFileType(FTP.BINARY_FILE_TYPE); return true; } } catch (Exception e) { this.error = e.getMessage(); } return false; }
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 {//from w w w. j a v a 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: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 a v a 2s.c o m 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:conf.FTPConf.java
public String subirArchivo(File archivo) { FTPClient ftpClient = new FTPClient(); try {/*w w w . j av a2 s. c o m*/ ftpClient.connect(server, port); ftpClient.login(user, pass); ftpClient.enterLocalPassiveMode(); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); // APPROACH #2: uploads second file using an OutputStream String serverFile = dir + archivo.getName(); InputStream inputStream = new FileInputStream(archivo); OutputStream outputStream = ftpClient.storeFileStream(serverFile); byte[] bytesIn = new byte[4096]; int read = 0; while ((read = inputStream.read(bytesIn)) != -1) { outputStream.write(bytesIn, 0, read); } inputStream.close(); outputStream.close(); boolean completed = ftpClient.completePendingCommand(); if (completed) { String link = "ftp://" + user + "@" + server + "/" + serverFile; return link; } } 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(); } } return null; }
From source file:boosta.artem.services.FTPResultReader.java
public void readResult() { String server = "62.210.82.210"; int port = 55021; String user = "misha_p"; String pass = "GfhjkM1983"; FTPClient ftpClient = new FTPClient(); try {//from www. j av a2 s .c o m ftpClient.connect(server, port); ftpClient.login(user, pass); ftpClient.enterLocalPassiveMode(); ftpClient.setFileType(FTP.ASCII_FILE_TYPE); // APPROACH #1: using retrieveFile(String, OutputStream) String remoteFile = Main.remote_out_path; System.out.println(remoteFile); //String remoteFile = "/results/ttgenerate.txt"; String downlFile = Main.file_name; System.out.println(downlFile); File downloadFile = new File(downlFile); OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(downloadFile)); boolean success = ftpClient.retrieveFile(remoteFile, outputStream); outputStream.close(); if (success) { System.out.println(" ? FTP!!!"); } else { System.out.println(" ? TFP!!!"); } } catch (IOException ex) { System.out.println(" ? FTP !!!"); } finally { try { if (ftpClient.isConnected()) { ftpClient.logout(); ftpClient.disconnect(); } } catch (IOException ex) { System.out.println(" ? ?? ? FTP!!!"); } } }
From source file:com.mendhak.gpslogger.senders.ftp.Ftp.java
public static boolean Upload(String server, String username, String password, int port, boolean useFtps, String protocol, boolean implicit, InputStream inputStream, String fileName) { FTPClient client = null;//w w w. j ava 2 s . co m try { if (useFtps) { client = new FTPSClient(protocol, implicit); KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmf.init(null, null); KeyManager km = kmf.getKeyManagers()[0]; ((FTPSClient) client).setKeyManager(km); } else { client = new FTPClient(); } } catch (Exception e) { e.printStackTrace(); } try { Utilities.LogDebug("Connecting to FTP"); client.connect(server, port); Utilities.LogDebug("Logging in to FTP server"); if (client.login(username, password)) { client.enterLocalPassiveMode(); Utilities.LogDebug("Uploading file to FTP server"); FTPFile[] existingDirectory = client.listFiles("GPSLogger"); if (existingDirectory.length <= 0) { client.makeDirectory("GPSLogger"); } client.changeWorkingDirectory("GPSLogger"); boolean result = client.storeFile(fileName, inputStream); inputStream.close(); if (result) { Utilities.LogDebug("Successfully FTPd file"); } else { Utilities.LogDebug("Failed to FTP file"); } } else { Utilities.LogDebug("Could not log in to FTP server"); return false; } } catch (Exception e) { Utilities.LogError("Could not connect or upload to FTP server.", e); } finally { try { Utilities.LogDebug("Logging out of FTP server"); client.logout(); Utilities.LogDebug("Disconnecting from FTP server"); client.disconnect(); } catch (Exception e) { Utilities.LogError("Could not logout or disconnect", e); } } return true; }
From source file:br.com.tiagods.util.FTPDownload.java
public boolean downloadFile(String arquivo) { FTPConfig cf = FTPConfig.getInstance(); FTPClient ftp = new FTPClient(); try {/*from ww w .j a v a 2 s . c o m*/ ftp.connect(cf.getValue("host"), Integer.parseInt(cf.getValue("port"))); ftp.login(cf.getValue("user"), cf.getValue("pass")); ftp.enterLocalPassiveMode(); ftp.setFileType(FTP.BINARY_FILE_TYPE); String remoteFile1 = cf.getValue("dirFTP") + "/" + arquivo; novoArquivo = new File(System.getProperty("java.io.tmpdir") + "/" + arquivo); try (OutputStream outputStream1 = new BufferedOutputStream(new FileOutputStream(novoArquivo))) { boolean success = ftp.retrieveFile(remoteFile1, outputStream1); if (success) { return true; } } return false; } catch (IOException e) { System.out.println("Erro = " + e.getMessage()); return false; } finally { try { if (ftp.isConnected()) { ftp.logout(); ftp.disconnect(); } } catch (IOException ex) { ex.printStackTrace(); } } }
From source file:com.dv.upgrade.DVUpgradeUtil.java
public static boolean init() { ftpClient = new FTPClient(); try {//w w w . j a v a2s .c o m ftpClient.connect(DVPropMain.DV_AUTO_UPDATE_SERVER, 21); if (!ftpClient.login(DVPropMain.DV_AUTO_UPDATE_SERVER_USER, DataViewerDesEncrypter.decrypt(DVPropMain.DV_AUTO_UPDATE_SERVER_PASSWORD))) { return false; } ftpClient.setControlEncoding("UTF-8"); ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); ftpClient.changeWorkingDirectory(getFtpPath()); } catch (Exception e) { DVLOG.setErrorLog(DVUpgradeUtil.class.getName(), e); return false; } return true; }
From source file:models.FtpFileDownloader.java
public FtpFileDownloader(String ftp_addr, ArrayList<String> all_files) { this.ftp_address = ftp_addr; ftpClient = new FTPClient(); all_files_on_ftp = all_files;/*from w w w . ja v a2 s .c o m*/ }