org.apache.commons.net.ftp.FTPCmd Java Examples
The following examples show how to use
org.apache.commons.net.ftp.FTPCmd.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PooledFTPOperationHandler.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 6 votes |
/** * Implementation using the MLST command, if available. * * @param targetUri * @param ftp * @return */ private Info info(URI targetUri, FTPClient ftp) { try { if (ftp.hasFeature(FTPCmd.MLST.getCommand())) { // Pure-FTPd does not understand .. and . in the path, hence we use URI.normalize() String path = getPath(targetUri.normalize()); if (path.equals(URIUtils.PATH_SEPARATOR)) { // CLO-4118: root directory, GlobalScape EFT disallows MLST FTPFile root = new FTPFile(); root.setType(FTPFile.DIRECTORY_TYPE); root.setName(""); return info(root, null, targetUri); } FTPFile file = mlistFile(ftp, path); if (file != null) { return new FTPInfo(file, null, targetUri); } else { return null; } } } catch (IOException ioe) { log.debug(MessageFormat.format("File metadata reading failed: {0}", targetUri), ioe); } return infoFallback(targetUri, ftp); }
Example #2
Source File: FTPRemoteDownloadSourceDelegate.java From datacollector with Apache License 2.0 | 6 votes |
private void setupModTime() { // The FTP protocol's default way to list files gives very inaccurate/ambiguous/inconsistent timestamps (e.g. it's // common for many FTP servers to drop the HH:mm on files older than 6 months). Some FTP servers support the // MDTM command, which returns an accurate/correct timestamp, but not all servers support it. Here, we'll check if // MDTM is supported so we can use it later to get proper timestamps. Unfortunately, VFS does not expose a nice way // to use MDTM or to even get to the underlying FTPClient (VFS-257). We have to use reflection. supportsMDTM = false; FtpClient ftpClient = null; FtpFileSystem ftpFileSystem = (FtpFileSystem) remoteDir.getFileSystem(); try { ftpClient = ftpFileSystem.getClient(); getFtpClient = FTPClientWrapper.class.getDeclaredMethod("getFtpClient"); getFtpClient.setAccessible(true); FTPClient rawFtpClient = (FTPClient) getFtpClient.invoke(ftpClient); rawFtpClient.features(); supportsMDTM = rawFtpClient.getReplyString().contains(FTPCmd.MDTM.getCommand()); } catch (Exception e) { LOG.trace("Ignoring Exception when determining MDTM support", e); } finally { if (ftpClient != null) { ftpFileSystem.putClient(ftpClient); } } LOG.info("Using MDTM for more accurate timestamps: {}", supportsMDTM); }
Example #3
Source File: FTPClient.java From cyberduck with GNU General Public License v3.0 | 6 votes |
public List<String> list(final FTPCmd command, final String pathname) throws IOException { this.pret(command, pathname); Socket socket = _openDataConnection_(command, pathname); BufferedReader reader = new BufferedReader( new InputStreamReader(socket.getInputStream(), getControlEncoding())); ArrayList<String> results = new ArrayList<String>(); String line; while((line = reader.readLine()) != null) { _commandSupport_.fireReplyReceived(-1, line); results.add(line); } reader.close(); socket.close(); if(!this.completePendingCommand()) { throw new FTPException(this.getReplyCode(), this.getReplyString()); } return results; }
Example #4
Source File: SynchronizationFtpTransferListener.java From ats-framework with Apache License 2.0 | 6 votes |
@Override public void protocolCommandSent( ProtocolCommandEvent event ) { /* because we can only pause a file upload, we check if the event has a STOR command */ if (event.getCommand().equals(FTPCmd.STOR.getCommand())) { // Check only progress events so the transfer be paused when the // transfer is taking place not before or after it. log.debug("Progress event #" + (currentProgessEvent)); if (currentProgessEvent++ == progressEventNumber && Thread.holdsLock(owner)) { try { log.debug("Waiting for the transfer to be resumed..."); // Release the monitor and wait to be notified to continue the transfer. owner.wait(); } catch (InterruptedException e) { log.error("Transfer thread interrupted while paused. Continue transfer.", e); } } } }
Example #5
Source File: FtpToDB_IT.java From syndesis with Apache License 2.0 | 5 votes |
@Test @CitrusTest public void testFtpToDB(@CitrusResource TestCaseRunner runner) { cleanupDatabase(runner); runner.given(receive() .endpoint(ftpTestServer) .timeout(Duration.ofSeconds(SyndesisTestEnvironment.getDefaultTimeout()).toMillis()) .message(FtpMessage.command(FTPCmd.RETR).arguments("todo.json"))); runner.when(send() .endpoint(ftpTestServer) .message(FtpMessage.success())); runner.then(repeatOnError() .startsWith(1) .autoSleep(1000L) .until(new IteratingConditionExpression() { @Override public boolean evaluate(int index, TestContext context) { return index > 10; } }) .actions(query(sampleDb) .statement("select count(*) as found_records from todo") .validate("found_records", String.valueOf(3)))); runner.then(query(sampleDb) .statement("select task, completed from todo") .validate("task", "FTP task #1", "FTP task #2", "FTP task #3") .validate("completed", "0", "1", "0")); }
Example #6
Source File: FtpSplitToDB_IT.java From syndesis with Apache License 2.0 | 5 votes |
@Test @CitrusTest public void testFtpSplitToDB(@CitrusResource TestCaseRunner runner) { cleanupDatabase(runner); runner.given(receive() .endpoint(ftpTestServer) .timeout(Duration.ofSeconds(SyndesisTestEnvironment.getDefaultTimeout()).toMillis()) .message(FtpMessage.command(FTPCmd.RETR).arguments("todo.json"))); runner.when(send() .endpoint(ftpTestServer) .message(FtpMessage.success())); runner.then(repeatOnError() .startsWith(1) .autoSleep(1000L) .until(new IteratingConditionExpression() { @Override public boolean evaluate(int index, TestContext context) { return index > 10; } }) .actions(query(sampleDb) .statement("select count(*) as found_records from todo") .validate("found_records", String.valueOf(3)))); runner.then(query(sampleDb) .statement("select task, completed from todo") .validate("task", "FTP task #1", "FTP task #2", "FTP task #3") .validate("completed", "0", "1", "0")); }
Example #7
Source File: FtpTestSupport.java From syndesis with Apache License 2.0 | 5 votes |
@Bean public FtpServer ftpTestServer(DataConnectionConfiguration dataConnectionConfiguration) { FtpEndpointConfiguration endpointConfiguration = new FtpEndpointConfiguration(); endpointConfiguration.setAutoConnect(true); endpointConfiguration.setAutoLogin(true); endpointConfiguration.setAutoHandleCommands( String.join(",", FTPCmd.PORT.getCommand(), FTPCmd.MKD.getCommand(), FTPCmd.PWD.getCommand(), FTPCmd.CWD.getCommand(), FTPCmd.PASV.getCommand(), FTPCmd.NOOP.getCommand(), FTPCmd.SYST.getCommand(), FTPCmd.LIST.getCommand(), FTPCmd.NLST.getCommand(), FTPCmd.QUIT.getCommand(), FTPCmd.TYPE.getCommand())); endpointConfiguration.setPort(FTP_TEST_SERVER_PORT); FtpServer ftpServer = new FtpServer(endpointConfiguration); ftpServer.setUserManagerProperties(new ClassPathResource("ftp.server.properties", FtpTestSupport.class)); ftpServer.setAutoStart(true); ListenerFactory listenerFactory = new ListenerFactory(); listenerFactory.setDataConnectionConfiguration(dataConnectionConfiguration); ftpServer.setListenerFactory(listenerFactory); return ftpServer; }
Example #8
Source File: WebHookToFtp_IT.java From syndesis with Apache License 2.0 | 5 votes |
@Test @CitrusTest public void testWebHookToFtp(@CitrusResource TestCaseRunner runner) { cleanupDatabase(runner); runner.variable("first_name", "Joanne"); runner.variable("company", "Red Hat"); runner.variable("email", "[email protected]"); runner.when(http().client(webHookClient) .send() .post() .fork(true) .payload("{\"first_name\":\"${first_name}\",\"company\":\"${company}\",\"mail\":\"${email}\"}")); runner.then(receive() .endpoint(ftpTestServer) .message(FtpMessage.command(FTPCmd.STOR).arguments("tmp_contacts.csv"))); runner.then(send() .endpoint(ftpTestServer) .message(FtpMessage.success())); runner.then(receive() .endpoint(ftpTestServer) .message(FtpMessage.command(FTPCmd.RNFR).arguments("public/tmp_contacts.csv"))); runner.then(send() .endpoint(ftpTestServer) .message(FtpMessage.success())); runner.then(http().client(webHookClient) .receive() .response(HttpStatus.NO_CONTENT)); runner.run(new VerifyFtpUploadTestAction()); }
Example #9
Source File: LoggingProtocolCommandListener.java From cyberduck with GNU General Public License v3.0 | 5 votes |
@Override public void protocolCommandSent(final ProtocolCommandEvent event) { final String message = StringUtils.chomp(event.getMessage()); if(message.startsWith(FTPCmd.PASS.name())) { this.log(Type.request, String.format("%s %s", FTPCmd.PASS.name(), StringUtils.repeat("*", StringUtils.length(StringUtils.removeStart(message, FTPCmd.PASS.name()))))); } else { this.log(Type.request, message); } }
Example #10
Source File: FTPAttributesFinderFeature.java From cyberduck with GNU General Public License v3.0 | 5 votes |
@Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } try { if(session.getClient().hasFeature(FTPCmd.MLST.getCommand())) { if(!FTPReply.isPositiveCompletion(session.getClient().sendCommand(FTPCmd.MLST, file.getAbsolute()))) { throw new FTPException(session.getClient().getReplyCode(), session.getClient().getReplyString()); } final FTPDataResponseReader reader = new FTPMlsdListResponseReader(); final AttributedList<Path> attributes = reader.read(file.getParent(), Arrays.asList(session.getClient().getReplyStrings()), new DisabledListProgressListener()); if(attributes.contains(file)) { return attributes.get(attributes.indexOf(file)).attributes(); } } throw new InteroperabilityException("No support for MLST in reply to FEAT"); } catch(IOException e) { throw new FTPExceptionMappingService().map("Failure to read attributes of {0}", e, file); } }
Example #11
Source File: FTPClient.java From cyberduck with GNU General Public License v3.0 | 5 votes |
/** * http://drftpd.org/index.php/PRET_Specifications * * @param command Command to execute * @param file Remote file * @throws IOException I/O failure */ protected void pret(final FTPCmd command, final String file) throws IOException { if(this.hasFeature("PRET")) { if(!FTPReply.isPositiveCompletion(this.sendCommand("PRET", String.format("%s %s", command.getCommand(), file)))) { throw new FTPException(this.getReplyCode(), this.getReplyString()); } } }
Example #12
Source File: FTPClient.java From cyberduck with GNU General Public License v3.0 | 4 votes |
@Override public boolean retrieveFile(String remote, OutputStream local) throws IOException { this.pret(FTPCmd.RETR, remote); return super.retrieveFile(remote, local); }
Example #13
Source File: PooledFTPOperationHandler.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 4 votes |
/** * CLO-4118: * Performs the MLST command. * Copied from {@link FTPClient#mlistFile(String)}. * * GlobalScape EFT does not return the leading space, * as required by <a href="http://tools.ietf.org/html/rfc3659#section-7.2">RFC 3659</a>. * This causes the entry to be stripped of the first character * - the "Type" fact is turned to "ype". * * @param ftp FTP client * @param pathname remote path * @return FTPFile or <code>null</code> * @throws IOException * * @see {@link FTPClient#mlistFile(String)} * @see <a href="http://tools.ietf.org/html/rfc3659#section-7.2">RFC 3659 - Extensions to FTP</a> */ private FTPFile mlistFile(FTPClient ftp, String pathname) throws IOException { boolean success = FTPReply.isPositiveCompletion(ftp.sendCommand(FTPCmd.MLST, pathname)); if (success) { String entry = ftp.getReplyStrings()[1]; char firstChar = entry.charAt(0); if (UnicodeBlanks.isBlank(firstChar)) { // skip leading space for parser entry = entry.substring(1); } return MLSxEntryParser.parseEntry(entry); } else { return null; } // return ftp.mlistFile(pathname); }
Example #14
Source File: FTPClient.java From cyberduck with GNU General Public License v3.0 | 4 votes |
@Override public OutputStream appendFileStream(String remote) throws IOException { this.pret(FTPCmd.APPE, remote); return super.appendFileStream(remote); }
Example #15
Source File: FTPClient.java From cyberduck with GNU General Public License v3.0 | 4 votes |
@Override public boolean appendFile(String remote, InputStream local) throws IOException { this.pret(FTPCmd.APPE, remote); return super.appendFile(remote, local); }
Example #16
Source File: FTPClient.java From cyberduck with GNU General Public License v3.0 | 4 votes |
@Override public OutputStream storeFileStream(String remote) throws IOException { this.pret(FTPCmd.STOR, remote); return super.storeFileStream(remote); }
Example #17
Source File: FTPClient.java From cyberduck with GNU General Public License v3.0 | 4 votes |
@Override public boolean storeFile(String remote, InputStream local) throws IOException { this.pret(FTPCmd.STOR, remote); return super.storeFile(remote, local); }
Example #18
Source File: FTPClient.java From cyberduck with GNU General Public License v3.0 | 4 votes |
@Override public InputStream retrieveFileStream(String remote) throws IOException { this.pret(FTPCmd.RETR, remote); return super.retrieveFileStream(remote); }
Example #19
Source File: FTPClient.java From cyberduck with GNU General Public License v3.0 | 4 votes |
public List<String> list(final FTPCmd command) throws IOException { return this.list(command, null); }
Example #20
Source File: FTPListService.java From cyberduck with GNU General Public License v3.0 | 4 votes |
public FTPCmd getCommand() { return command; }
Example #21
Source File: FTPListService.java From cyberduck with GNU General Public License v3.0 | 4 votes |
Command(FTPCmd command, String arg) { this.command = command; this.arg = arg; }
Example #22
Source File: FTPListService.java From cyberduck with GNU General Public License v3.0 | 4 votes |
Command(FTPCmd command) { this(command, null); }
Example #23
Source File: PooledFTPOperationHandler.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 3 votes |
/** * If available, lists directory contents using the MLSD command. * Otherwise uses LIST command. * * @param path * @param ftp * @return * @throws IOException */ private FTPFile[] listFiles(String path, FTPClient ftp) throws IOException { if (ftp.hasFeature(FTPCmd.MLSD.getCommand())) { return ftp.mlistDir(path); } else { return ftp.listFiles(path); } }