List of usage examples for org.apache.commons.net.ftp FTPClient FTPClient
public FTPClient()
From source file:heigit.ors.routing.traffic.providers.FtpDataSource.java
@Override public String getMessage() throws IOException { String message = null;//from w w w .j a v a2 s . c o m try { FTPClient ftpClient = new FTPClient(); ftpClient.connect(server, port); ftpClient.login(user, password); ftpClient.enterLocalPassiveMode(); ftpClient.setFileType(2); String remoteFile1 = "/" + file; InputStream inputStream = ftpClient.retrieveFileStream(remoteFile1); message = StreamUtility.readStream(inputStream, "iso-8859-1"); Boolean success = ftpClient.completePendingCommand(); if (success) { System.out.println("File has been downloaded successfully."); } inputStream.close(); } catch (IOException e) { /* SendMail mail = new SendMail(); try { mail.postMail(this.properties.getProperty("mail"), "TMC-Fehler", e.getStackTrace().toString(), "TMC@Fehlermeldung.de", this.properties .getProperty("smtpHost"), this.properties .getProperty("smtpUser"), this.properties .getProperty("smtpPort")); } catch (MessagingException e1) { e1.printStackTrace(); } this.logger.debug("Error with FTP connection " + e.getLocalizedMessage(), e); throw new DownloadException( "Error while downloading file from FTP " + e.getLocalizedMessage(), e); */ } return message; }
From source file:it.zero11.acme.example.FTPChallengeListener.java
private boolean createChallengeFiles(String token, String challengeBody) { boolean success = false; FTPClient ftp = new FTPClient(); try {/*from w w w.j a v a 2s . c om*/ ftp.connect(host); if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) { ftp.disconnect(); return false; } ftp.login(username, password); ftp.changeWorkingDirectory(webroot); ftp.makeDirectory(".well-known"); ftp.changeWorkingDirectory(".well-known"); ftp.makeDirectory("acme-challenge"); ftp.changeWorkingDirectory("acme-challenge"); ftp.enterLocalPassiveMode(); ftp.setFileType(FTPClient.BINARY_FILE_TYPE, FTPClient.BINARY_FILE_TYPE); ftp.setFileTransferMode(FTPClient.BINARY_FILE_TYPE); success = ftp.storeFile(token, new ByteArrayInputStream(challengeBody.getBytes())); if (!success) System.err.println("FTP error uploading file: " + ftp.getReplyCode() + ": " + ftp.getReplyString()); ftp.logout(); } catch (IOException e) { throw new AcmeException(e); } finally { if (ftp.isConnected()) { try { ftp.disconnect(); } catch (IOException ioe) { } } } return success; }
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. ja va2s .c o m 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:com.igormaznitsa.zxpoly.utils.ROMLoader.java
static byte[] loadFTPArchive(final String host, final String path, final String name, final String password) throws IOException { final FTPClient client = new FTPClient(); client.connect(host);//from w w w . j a v a 2 s .c o m int replyCode = client.getReplyCode(); if (FTPReply.isPositiveCompletion(replyCode)) { try { client.login(name == null ? "" : name, password == null ? "" : password); client.setFileType(FTP.BINARY_FILE_TYPE); client.enterLocalPassiveMode(); final ByteArrayOutputStream out = new ByteArrayOutputStream(300000); if (client.retrieveFile(path, out)) { return out.toByteArray(); } else { throw new IOException( "Can't load file 'ftp://" + host + path + "\' status=" + client.getReplyCode()); } } finally { client.disconnect(); } } else { client.disconnect(); throw new IOException("Can't connect to ftp '" + host + "'"); } }
From source file:com.webarch.common.net.ftp.FtpService.java
/** * /*from w w w. j ava2s.c o m*/ * * @param fileName ?? * @param path ftp? * @param fileStream ? * @return true/false ? */ public boolean uploadFile(String fileName, String path, InputStream fileStream) { boolean success = false; FTPClient ftpClient = new FTPClient(); try { int replyCode; ftpClient.connect(url, port); ftpClient.login(userName, password); replyCode = ftpClient.getReplyCode(); if (!FTPReply.isPositiveCompletion(replyCode)) { return false; } ftpClient.changeWorkingDirectory(path); ftpClient.storeFile(fileName, fileStream); fileStream.close(); ftpClient.logout(); success = true; } catch (IOException e) { logger.error("ftp?", e); } finally { if (ftpClient.isConnected()) { try { ftpClient.disconnect(); } catch (IOException e) { logger.error("ftp?", e); } } } return success; }
From source file:com.adaptris.core.ftp.ClientSettingsTest.java
@Test(expected = RuntimeException.class) public void testPreConnectSettings_FTP_Error() { FTPClient client = new FTPClient(); Map<String, String> settings = createFtpSettings(); // Should throw a NumberFormatException, which is then wrapped settings.put(FTP.SendDataSocketBufferSize.name(), "XXX"); preConnectSettings(client, FTP.values(), settings); }
From source file:com.shadwelldacunha.byteswipe.connection.FTPHelper.java
public FTPHelper(String host, String username, String password, int port) { super(host, username, password, port); //TODO: Handle proxy this.ftp = new FTPClient(); //TODO: Handle set hidden files through config this.ftp.setListHiddenFiles(true); }
From source file:eu.ggnet.dwoss.misc.op.listings.FtpTransfer.java
/** * Uploads a some files to a remove ftp host. * <p/>/* w w w.j a v a2 s . c o m*/ * @param config the config for he connection. * @param uploads the upload commands * @param monitor an optional monitor. * @throws java.net.SocketException * @throws java.io.IOException */ public static void upload(ConnectionConfig config, IMonitor monitor, UploadCommand... uploads) throws SocketException, IOException { if (uploads == null || uploads.length == 0) return; SubMonitor m = SubMonitor.convert(monitor, "FTP Transfer", toWorkSize(uploads) + 4); m.message("verbinde"); m.start(); FTPClient ftp = new FTPClient(); ftp.addProtocolCommandListener(PROTOCOL_TO_LOGGER); try { ftp.connect(config.getHost(), config.getPort()); if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) throw new IOException("FTPReply.isPositiveCompletion(ftp.getReplyCode()) = false"); if (!ftp.login(config.getUser(), config.getPass())) throw new IOException("Login with " + config.getUser() + " not successful"); L.info("Connected to {} idenfied by {}", config.getHost(), ftp.getSystemType()); ftp.setFileType(FTP.BINARY_FILE_TYPE); ftp.enterLocalPassiveMode(); for (UploadCommand upload : uploads) { m.worked(1, "uploading to " + upload.getPath()); ftp.changeWorkingDirectory(upload.getPath()); deleteFilesByType(ftp, upload.getDeleteFileTypes()); for (File file : upload.getFiles()) { m.worked(1, "uploading to " + upload.getPath() + " file " + file.getName()); try (InputStream input = new FileInputStream(file)) { if (!ftp.storeFile(file.getName(), input)) throw new IOException("Cannot store file " + file + " on server!"); } } } m.finish(); } finally { // just cleaning up try { ftp.logout(); } catch (IOException e) { } if (ftp.isConnected()) { try { ftp.disconnect(); } catch (IOException f) { } } } }
From source file:FTP.FileUploading.java
private void init(String SUUID, String CUUID, String Server, String User, String Pass, String LFile, String RFile) {/* w w w . j a v a2 s .c o m*/ try { ftpClient = new FTPClient(); ftpClient.connect(Server); ftpClient.login(User, Pass); ftpClient.enterLocalPassiveMode(); ftpClient.setKeepAlive(true); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); this.ServerUUID = SUUID; this.ClientUUID = CUUID; this.LocalFile = LFile; this.RemotFile = RFile; } catch (IOException ex) { ftpClient = null; init(SUUID, CUUID, Server, User, Pass, LFile, RFile); } }
From source file:models.Indexer.java
public Indexer(String ftp_addr) { // documents_queue = new LinkedList(); ftp_address = ftp_addr; ftpClient = new FTPClient(); }