List of usage examples for org.apache.commons.net.ftp FTPClientConfig SYST_UNIX
String SYST_UNIX
To view the source code for org.apache.commons.net.ftp FTPClientConfig SYST_UNIX.
Click Source Link
From source file:ch.cyberduck.core.ftp.parser.CommonUnixFTPEntryParser.java
/** * Defines a default configuration to be used when this class is * instantiated without a {@link FTPClientConfig FTPClientConfig} * parameter being specified.//from w w w .ja va 2 s. c om * * @return the default configuration for this parser. */ @Override protected FTPClientConfig getDefaultConfiguration() { final FTPClientConfig config = new FTPClientConfig(FTPClientConfig.SYST_UNIX, FTPTimestampParser.DEFAULT_SDF, FTPTimestampParser.DEFAULT_RECENT_SDF, null, null, null); config.setLenientFutureDates(true); return config; }
From source file:ch.cyberduck.core.ftp.FTPParserFactory.java
public CompositeFileEntryParser createFileEntryParser(final String system, final TimeZone timezone) throws ParserInitializationException { if (null != system) { String ukey = system.toUpperCase(Locale.ROOT); if (ukey.contains(FTPClientConfig.SYST_UNIX)) { return this.createUnixFTPEntryParser(timezone); } else if (ukey.contains(FTPClientConfig.SYST_VMS)) { throw new ParserInitializationException( String.format("\"%s\" is not currently a supported system.", system)); } else if (ukey.contains(FTPClientConfig.SYST_NETWARE)) { return this.createNetwareFTPEntryParser(timezone); } else if (ukey.contains(FTPClientConfig.SYST_NT)) { return this.createNTFTPEntryParser(timezone); } else if (ukey.contains(FTPClientConfig.SYST_OS2)) { return this.createOS2FTPEntryParser(timezone); } else if (ukey.contains(FTPClientConfig.SYST_OS400)) { return this.createOS400FTPEntryParser(timezone); } else if (ukey.contains(FTPClientConfig.SYST_MVS)) { return this.createUnixFTPEntryParser(timezone); }/* w w w . j a va 2s.com*/ } // Defaulting to UNIX parser return this.createUnixFTPEntryParser(timezone); }
From source file:com.streamsets.pipeline.stage.origin.remote.FTPAndSSHDUnitTest.java
protected void setupFTPServer(String homeDir) throws Exception { fakeFtpServer = new SessionTrackingFakeFtpServer(); fakeFtpServer.setServerControlPort(0); fakeFtpServer.setSystemName(FTPClientConfig.SYST_UNIX); fakeFtpServer.setFileSystem(new UnixFakeFileSystem()); UserAccount userAccount = new UserAccount(TESTUSER, TESTPASS, homeDir); fakeFtpServer.addUserAccount(userAccount); fakeFtpServer.start();/*from w w w . java 2s . com*/ port = fakeFtpServer.getServerControlPort(); populateFakeFileSystemFromReal(new File(homeDir)); // Add the missing FEAT and MDTM commands fakeFtpServer.setCommandHandler(FTPCmd.FEAT.getCommand(), new StaticReplyCommandHandler(211, "MDTM")); fakeFtpServer.setCommandHandler(FTPCmd.MDTM.getCommand(), new AbstractStubCommandHandler() { @Override protected void handleCommand(Command command, Session session, InvocationRecord invocationRecord) { String pathname = command.getOptionalString(0); if (!pathname.startsWith("/")) { pathname = homeDir + "/" + pathname; } invocationRecord.set(StatCommandHandler.PATHNAME_KEY, pathname); FileSystemEntry file = fakeFtpServer.getFileSystem().getEntry(pathname); if (file == null) { sendReply(session, 550, null, "No such file or directory.", null); } else { String time = MDTM_DATE_FORMAT.format(file.getLastModified()); sendReply(session, 213, null, time, null); } } }); }
From source file:it.greenvulcano.util.remotefs.ftp.FTPManager.java
/** * @see it.greenvulcano.util.remotefs.RemoteManager#init(Node) *///from w w w.jav a 2 s. c om @Override public void init(Node node) throws RemoteManagerException { super.init(node); try { hostType = TargetType.valueOf(XMLConfig.get(node, "@hostType")); logger.debug("host-type : " + hostType); FTPClientConfig conf = null; switch (hostType) { case MVS: { conf = new FTPClientConfig(FTPClientConfig.SYST_MVS); break; } case NT: { conf = new FTPClientConfig(FTPClientConfig.SYST_NT); break; } case OS2: { conf = new FTPClientConfig(FTPClientConfig.SYST_OS2); break; } case OS400: { conf = new FTPClientConfig(FTPClientConfig.SYST_OS400); break; } case UNIX: { conf = new FTPClientConfig(FTPClientConfig.SYST_UNIX); break; } case VMS: { conf = new FTPClientConfig(FTPClientConfig.SYST_VMS); break; } } ftpClient.configure(conf); ftpClient.setDefaultTimeout(connectTimeout); ftpClient.setDataTimeout(dataTimeout); } catch (Exception exc) { throw new RemoteManagerException("Initialization error", exc); } }
From source file:com.symbian.driver.plugins.ftptelnet.FtpTransfer.java
/** * connectFTP : connects to ftp server/*from w ww . ja v a 2 s . c o m*/ * * @return boolean success/fail */ public boolean connectFTP() { if (isFTPConnected()) { return true; } // Connect to FTP try { // 1. create an apache client iFTP = new FTPClient(); iFTP.addProtocolCommandListener(new ProtocolCommandListener() { public void protocolCommandSent(ProtocolCommandEvent aProtocolCommandEvent) { LOGGER.fine("FTP Command Send: (" + aProtocolCommandEvent.getCommand() + ") " + aProtocolCommandEvent.getMessage()); } public void protocolReplyReceived(ProtocolCommandEvent aProtocolCommandEvent) { LOGGER.fine("FTP Command Recieved: (" + aProtocolCommandEvent.getMessage() + ") Returned Code " + aProtocolCommandEvent.getReplyCode()); } }); FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_UNIX); iFTP.configure(conf); // 2. connect iFTP.connect(iIP, iPort); // 3. check connection done. int reply = iFTP.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { disconnectFTP(); LOGGER.log(Level.SEVERE, "FTP error: " + reply); return false; } // 4. Login if (!iFTP.login(iUserName, iPassword)) { LOGGER.log(Level.SEVERE, "FTP failed to login, Username: " + iUserName + " Password: " + iPassword); disconnectFTP(); return false; } else { if (iPassive.equalsIgnoreCase("true")) { iFTP.enterLocalPassiveMode(); } iFTP.setFileType(FTP.BINARY_FILE_TYPE); iFTP.setBufferSize(iBufferSize); } } catch (SocketException lSocketException) { LOGGER.log(Level.SEVERE, "Socket exception ", lSocketException); return false; } catch (IOException lIOException) { LOGGER.log(Level.SEVERE, "Socket exception ", lIOException); return false; } LOGGER.info("FTP connection established with transport : " + iIP + ":" + iPort); return true; }
From source file:com.ai.api.util.UnixFTPEntryParser.java
/** * Defines a default configuration to be used when this class is * instantiated without a {@link FTPClientConfig FTPClientConfig} * parameter being specified./* ww w. j a va 2 s . com*/ * @return the default configuration for this parser. */ protected FTPClientConfig getDefaultConfiguration() { return new FTPClientConfig(FTPClientConfig.SYST_UNIX, DEFAULT_DATE_FORMAT, DEFAULT_RECENT_DATE_FORMAT, null, null, null); }
From source file:net.seedboxer.common.ftp.FtpUploaderCommons.java
/** * List files inside the current folder. * /*from w w w .ja v a 2s. co m*/ * @return List with files names and size * @throws IOException */ private Map<String, Long> listFiles() throws FtpException { int attempts = 0; Map<String, Long> files = new LinkedHashMap<String, Long>(); while (true) { try { FTPListParseEngine engine = null; if (type.startsWith("UNIX")) { engine = ftpClient.initiateListParsing(FTPClientConfig.SYST_UNIX, null); } else { engine = ftpClient.initiateListParsing(); } FTPFile[] list = engine.getFiles(); if (list != null) { for (FTPFile ftpFile : list) { files.put(ftpFile.getName(), ftpFile.getSize()); } } return files; } catch (Exception e) { attempts++; if (attempts > 3) { throw new FtpListFilesException(e); } else { LOGGER.trace("First attempt to get list of files FAILED! attempt={}", attempts); } } } }
From source file:com.clickha.nifi.processors.util.FTPTransferV2.java
private FTPClient getClient(final FlowFile flowFile) throws IOException { if (client != null) { String desthost = ctx.getProperty(HOSTNAME).evaluateAttributeExpressions(flowFile).getValue(); if (remoteHostName.equals(desthost)) { // destination matches so we can keep our current session resetWorkingDirectory();/*from w ww. j av a 2 s .c o m*/ return client; } else { // this flowFile is going to a different destination, reset session close(); } } final Proxy.Type proxyType = Proxy.Type.valueOf(ctx.getProperty(PROXY_TYPE).getValue()); final String proxyHost = ctx.getProperty(PROXY_HOST).getValue(); final Integer proxyPort = ctx.getProperty(PROXY_PORT).asInteger(); FTPClient client; if (proxyType == Proxy.Type.HTTP) { client = new FTPHTTPClient(proxyHost, proxyPort, ctx.getProperty(HTTP_PROXY_USERNAME).getValue(), ctx.getProperty(HTTP_PROXY_PASSWORD).getValue()); } else { client = new FTPClient(); if (proxyType == Proxy.Type.SOCKS) { client.setSocketFactory(new SocksProxySocketFactory( new Proxy(proxyType, new InetSocketAddress(proxyHost, proxyPort)))); } } this.client = client; client.setDataTimeout(ctx.getProperty(DATA_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue()); client.setDefaultTimeout( ctx.getProperty(CONNECTION_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue()); client.setRemoteVerificationEnabled(false); final String remoteHostname = ctx.getProperty(HOSTNAME).evaluateAttributeExpressions(flowFile).getValue(); this.remoteHostName = remoteHostname; InetAddress inetAddress = null; try { inetAddress = InetAddress.getByAddress(remoteHostname, null); } catch (final UnknownHostException uhe) { } if (inetAddress == null) { inetAddress = InetAddress.getByName(remoteHostname); } client.connect(inetAddress, ctx.getProperty(PORT).evaluateAttributeExpressions(flowFile).asInteger()); this.closed = false; client.setDataTimeout(ctx.getProperty(DATA_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue()); client.setSoTimeout(ctx.getProperty(CONNECTION_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue()); final String username = ctx.getProperty(USERNAME).evaluateAttributeExpressions(flowFile).getValue(); final String password = ctx.getProperty(PASSWORD).evaluateAttributeExpressions(flowFile).getValue(); final boolean loggedIn = client.login(username, password); if (!loggedIn) { throw new IOException("Could not login for user '" + username + "'"); } final String connectionMode = ctx.getProperty(CONNECTION_MODE).getValue(); if (connectionMode.equalsIgnoreCase(CONNECTION_MODE_ACTIVE)) { client.enterLocalActiveMode(); } else { client.enterLocalPassiveMode(); } // additional FTPClientConfig ftpConfig = new FTPClientConfig(FTPClientConfig.SYST_UNIX); final String ftpClientConfig = ctx.getProperty(FTP_CLIENT_CONFIG_SYST).getValue(); if (ftpClientConfig.equalsIgnoreCase(FTP_CLIENT_CONFIG_SYST_UNIX)) { this.ftpConfig = ftpConfig; client.configure(ftpConfig); } else if (ftpClientConfig.equalsIgnoreCase(FTP_CLIENT_CONFIG_SYST_NT)) { this.ftpConfig = ftpConfig; client.configure(ftpConfig); } final String transferMode = ctx.getProperty(TRANSFER_MODE).getValue(); final int fileType = (transferMode.equalsIgnoreCase(TRANSFER_MODE_ASCII)) ? FTPClient.ASCII_FILE_TYPE : FTPClient.BINARY_FILE_TYPE; if (!client.setFileType(fileType)) { throw new IOException("Unable to set transfer mode to type " + transferMode); } this.homeDirectory = client.printWorkingDirectory(); return client; }
From source file:org.apache.camel.component.file.remote.FtpConsumerUsingFTPClientConfigTest.java
private FTPClientConfig createConfig() { FTPClientConfig config = new FTPClientConfig(FTPClientConfig.SYST_UNIX); config.setServerTimeZoneId("Europe/Paris"); return config; }
From source file:org.apache.sqoop.connector.mainframe.MainframeFTPClientUtils.java
public static FTPClient getFTPConnection(TransferableContext context, LinkConfiguration linkConfiguration) throws IOException { FTPClient ftp = null;//w ww. jav a 2 s . c om try { String username = linkConfiguration.linkConfig.username; String password; if (username == null) { username = "anonymous"; password = ""; } else { password = linkConfiguration.linkConfig.password; } String connectString = linkConfiguration.linkConfig.uri; String server = connectString; int port = 0; String[] parts = connectString.split(":"); if (parts.length == 2) { server = parts[0]; try { port = Integer.parseInt(parts[1]); } catch (NumberFormatException e) { LOG.warn("Invalid port number: " + e.toString()); } } if (null != mockFTPClient) { ftp = mockFTPClient; } else { ftp = new FTPClient(); } // The following section to get the system key for FTPClientConfig is just there for testing purposes String systemKey = null; String systemTypeString = context.getString("spark.mainframe.connector.system.type", "MVS"); if (systemTypeString.equals("MVS")) { systemKey = FTPClientConfig.SYST_MVS; } else if (systemTypeString.equals("UNIX")) { systemKey = FTPClientConfig.SYST_UNIX; } else { assert (false); } FTPClientConfig config = new FTPClientConfig(systemKey); ftp.configure(config); try { if (port > 0) { ftp.connect(server, port); } else { ftp.connect(server); } } catch (IOException ioexp) { throw new IOException("Could not connect to server " + server, ioexp); } int reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { throw new IOException("FTP server " + server + " refused connection:" + ftp.getReplyString()); } LOG.info("Connected to " + server + " on " + (port > 0 ? port : ftp.getDefaultPort())); if (!ftp.login(username, password)) { ftp.logout(); throw new IOException("Could not login to server " + server + ":" + ftp.getReplyString()); } // set ASCII transfer mode ftp.setFileType(FTP.ASCII_FILE_TYPE); // Use passive mode as default. ftp.enterLocalPassiveMode(); } catch (IOException ioe) { if (ftp != null && ftp.isConnected()) { try { ftp.disconnect(); } catch (IOException f) { // do nothing } } ftp = null; throw ioe; } return ftp; }