List of usage examples for org.apache.commons.net.ftp FTPClientConfig setServerLanguageCode
public void setServerLanguageCode(String serverLanguageCode)
setter for the serverLanguageCode property.
From source file:Main.java
private static FTPClientConfig getFTPClientConfig() { FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_NT); conf.setServerLanguageCode("zh"); return conf;/*w w w. ja v a 2s . c o m*/ }
From source file:com.usefullc.platform.common.utils.FtpUtils.java
/** * /*from w w w. ja v a2 s . co m*/ * * @param oppositePath * @param downFileName ?? * @return */ public static InputStream download(String oppositePath, String downFileName) { InputStream is = null; try { // // ftpClient.connect(host, port); // ftpClient.login(user, password); // ?? int reply = ftpClient.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { log.error("FTP server refused connection,host=" + host + ",user=" + user + "," + password); return is; } FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_NT); conf.setServerLanguageCode("zh"); String sep = "/"; String workRemoteDir = StrUtils.joinEmpty(remoteDir, sep, oppositePath); FTPFile[] remoteFiles = ftpClient.listFiles(workRemoteDir); if (remoteFiles != null) { for (int i = 0; i < remoteFiles.length; i++) { String name = remoteFiles[i].getName(); if (!name.equals(downFileName)) { continue; } // String sep = File.separator; String fileName = StrUtils.joinEmpty(remoteDir, sep, oppositePath, sep, name); is = ftpClient.retrieveFileStream(fileName); } } ftpClient.logout(); } catch (Exception e) { e.printStackTrace(); } finally { try { ftpClient.disconnect(); } catch (IOException ioe) { ioe.printStackTrace(); } } return is; }
From source file:com.usefullc.platform.common.utils.FtpUtils.java
/** * /*from w ww. j av a2 s. com*/ * * @param oppositePath * @param uploadFileName ?? * @param is ? */ public static void upload(String oppositePath, String uploadFileName, InputStream is) { try { // ftpClient.connect(host, port); // ftpClient.login(user, password); // ?? int reply = ftpClient.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { log.error("FTP server refused connection,host=" + host + ",user=" + user + "," + password); return; } String sep = "/"; String workRemoteDir = StrUtils.joinEmpty(remoteDir, sep, oppositePath); // try { int n = workRemoteDir.indexOf("/", 1); String subRemoteDir = null; while (n != -1) { subRemoteDir = workRemoteDir.substring(0, n); if (!ftpClient.changeWorkingDirectory(subRemoteDir)) { ftpClient.makeDirectory(subRemoteDir); } n = workRemoteDir.indexOf("/", n + 1); } ftpClient.makeDirectory(workRemoteDir); } catch (IOException e1) { e1.printStackTrace(); } FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_NT); conf.setServerLanguageCode("zh"); // ftpClient.changeWorkingDirectory(workRemoteDir); ftpClient.setBufferSize(1024); ftpClient.setControlEncoding("GBK"); // ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); // boolean state = ftpClient.storeFile(uploadFileName, is); log.debug("storeFile state = " + state); ftpClient.logout(); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(is); try { ftpClient.disconnect(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.moosemorals.mediabrowser.FtpScanner.java
FtpScanner(PVR pvr, String remoteHostname) { this.pvr = pvr; this.remoteHostname = remoteHostname; FTPClientConfig config = new FTPClientConfig(); config.setServerTimeZoneId(DEFAULT_TIMEZONE.getID()); config.setServerLanguageCode("EN"); ftp = new FTPClient(); ftp.configure(config);// w ww .j a va 2 s .c om if (debugFTP) { ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true)); } ftpRunning = new AtomicBoolean(false); }
From source file:com.github.carlosrubio.org.apache.tools.ant.taskdefs.optional.net.FTPConfigurator.java
/** * configures the supplied FTPClient with the various * attributes set in the supplied FTP task. * @param client the FTPClient to be configured * @param task the FTP task whose attributes are used to * configure the client//from w w w . j a v a 2s . c o m * @return the client as configured. */ static FTPClient configure(FTPClient client, FTP task) { task.log("custom configuration", Project.MSG_VERBOSE); FTPClientConfig config; String systemTypeKey = task.getSystemTypeKey(); if (systemTypeKey != null && !"".equals(systemTypeKey)) { config = new FTPClientConfig(systemTypeKey); task.log("custom config: system key = " + systemTypeKey, Project.MSG_VERBOSE); } else { config = new FTPClientConfig(); task.log("custom config: system key = default (UNIX)", Project.MSG_VERBOSE); } String defaultDateFormatConfig = task.getDefaultDateFormatConfig(); if (defaultDateFormatConfig != null) { config.setDefaultDateFormatStr(defaultDateFormatConfig); task.log("custom config: default date format = " + defaultDateFormatConfig, Project.MSG_VERBOSE); } String recentDateFormatConfig = task.getRecentDateFormatConfig(); if (recentDateFormatConfig != null) { config.setRecentDateFormatStr(recentDateFormatConfig); task.log("custom config: recent date format = " + recentDateFormatConfig, Project.MSG_VERBOSE); } String serverLanguageCodeConfig = task.getServerLanguageCodeConfig(); if (serverLanguageCodeConfig != null) { if (!"".equals(serverLanguageCodeConfig) && !FTPClientConfig.getSupportedLanguageCodes().contains(serverLanguageCodeConfig)) { throw new BuildException("unsupported language code" + serverLanguageCodeConfig); } config.setServerLanguageCode(serverLanguageCodeConfig); task.log("custom config: server language code = " + serverLanguageCodeConfig, Project.MSG_VERBOSE); } String serverTimeZoneConfig = task.getServerTimeZoneConfig(); if (serverTimeZoneConfig != null) { config.setServerTimeZoneId(serverTimeZoneConfig); task.log("custom config: server time zone ID = " + serverTimeZoneConfig, Project.MSG_VERBOSE); } String shortMonthNamesConfig = task.getShortMonthNamesConfig(); if (shortMonthNamesConfig != null) { config.setShortMonthNames(shortMonthNamesConfig); task.log("custom config: short month names = " + shortMonthNamesConfig, Project.MSG_VERBOSE); } client.configure(config); return client; }
From source file:fr.acxio.tools.agia.ftp.DefaultFtpClientFactory.java
public FTPClient getFtpClient() throws IOException { FTPClient aClient = new FTPClient(); // Debug output // aClient.addProtocolCommandListener(new PrintCommandListener(new // PrintWriter(System.out), true)); if (activeExternalIPAddress != null) { aClient.setActiveExternalIPAddress(activeExternalIPAddress); }/*from ww w.j av a 2 s .com*/ if (activeMinPort != null && activeMaxPort != null) { aClient.setActivePortRange(activeMinPort, activeMaxPort); } if (autodetectUTF8 != null) { aClient.setAutodetectUTF8(autodetectUTF8); } if (bufferSize != null) { aClient.setBufferSize(bufferSize); } if (charset != null) { aClient.setCharset(charset); } if (connectTimeout != null) { aClient.setConnectTimeout(connectTimeout); } if (controlEncoding != null) { aClient.setControlEncoding(controlEncoding); } if (controlKeepAliveReplyTimeout != null) { aClient.setControlKeepAliveReplyTimeout(controlKeepAliveReplyTimeout); } if (controlKeepAliveTimeout != null) { aClient.setControlKeepAliveTimeout(controlKeepAliveTimeout); } if (dataTimeout != null) { aClient.setDataTimeout(dataTimeout); } if (defaultPort != null) { aClient.setDefaultPort(defaultPort); } if (defaultTimeout != null) { aClient.setDefaultTimeout(defaultTimeout); } if (fileStructure != null) { aClient.setFileStructure(fileStructure); } if (keepAlive != null) { aClient.setKeepAlive(keepAlive); } if (listHiddenFiles != null) { aClient.setListHiddenFiles(listHiddenFiles); } if (parserFactory != null) { aClient.setParserFactory(parserFactory); } if (passiveLocalIPAddress != null) { aClient.setPassiveLocalIPAddress(passiveLocalIPAddress); } if (passiveNatWorkaround != null) { aClient.setPassiveNatWorkaround(passiveNatWorkaround); } if (proxy != null) { aClient.setProxy(proxy); } if (receieveDataSocketBufferSize != null) { aClient.setReceieveDataSocketBufferSize(receieveDataSocketBufferSize); } if (receiveBufferSize != null) { aClient.setReceiveBufferSize(receiveBufferSize); } if (remoteVerificationEnabled != null) { aClient.setRemoteVerificationEnabled(remoteVerificationEnabled); } if (reportActiveExternalIPAddress != null) { aClient.setReportActiveExternalIPAddress(reportActiveExternalIPAddress); } if (sendBufferSize != null) { aClient.setSendBufferSize(sendBufferSize); } if (sendDataSocketBufferSize != null) { aClient.setSendDataSocketBufferSize(sendDataSocketBufferSize); } if (strictMultilineParsing != null) { aClient.setStrictMultilineParsing(strictMultilineParsing); } if (tcpNoDelay != null) { aClient.setTcpNoDelay(tcpNoDelay); } if (useEPSVwithIPv4 != null) { aClient.setUseEPSVwithIPv4(useEPSVwithIPv4); } if (systemKey != null) { FTPClientConfig aClientConfig = new FTPClientConfig(systemKey); if (defaultDateFormat != null) { aClientConfig.setDefaultDateFormatStr(defaultDateFormat); } if (recentDateFormat != null) { aClientConfig.setRecentDateFormatStr(recentDateFormat); } if (serverLanguageCode != null) { aClientConfig.setServerLanguageCode(serverLanguageCode); } if (shortMonthNames != null) { aClientConfig.setShortMonthNames(shortMonthNames); } if (serverTimeZoneId != null) { aClientConfig.setServerTimeZoneId(serverTimeZoneId); } aClient.configure(aClientConfig); } if (LOGGER.isInfoEnabled()) { LOGGER.info("Connecting to : {}", host); } if (port == null) { aClient.connect(host); } else { aClient.connect(host, port); } int aReplyCode = aClient.getReplyCode(); if (!FTPReply.isPositiveCompletion(aReplyCode)) { aClient.disconnect(); throw new IOException("Cannot connect to " + host + ". Returned code : " + aReplyCode); } try { if (localPassiveMode) { aClient.enterLocalPassiveMode(); } boolean aIsLoggedIn = false; if (account == null) { aIsLoggedIn = aClient.login(username, password); } else { aIsLoggedIn = aClient.login(username, password, account); } if (!aIsLoggedIn) { throw new IOException(aClient.getReplyString()); } } catch (IOException e) { aClient.disconnect(); throw e; } if (fileTransferMode != null) { aClient.setFileTransferMode(fileTransferMode); } if (fileType != null) { aClient.setFileType(fileType); } return aClient; }
From source file:org.apache.camel.component.file.remote.FromFtpClientConfigRefTest.java
@Override protected JndiRegistry createRegistry() throws Exception { JndiRegistry jndi = super.createRegistry(); FTPClientConfig config = new FTPClientConfig(); config.setServerLanguageCode("fr"); config.setLenientFutureDates(true);// w w w. ja va 2 s.com jndi.bind("myConfig", config); return jndi; }
From source file:org.apache.tools.ant.taskdefs.optional.net.FTPConfigurator.java
/** * configures the supplied FTPClient with the various * attributes set in the supplied FTP task. * @param client the FTPClient to be configured * @param task the FTP task whose attributes are used to * configure the client/*from w w w . ja va 2 s . co m*/ * @return the client as configured. */ static FTPClient configure(FTPClient client, FTPTaskConfig task) { task.log("custom configuration", Project.MSG_VERBOSE); FTPClientConfig config; String systemTypeKey = task.getSystemTypeKey(); if (systemTypeKey != null && !"".equals(systemTypeKey)) { config = new FTPClientConfig(systemTypeKey); task.log("custom config: system key = " + systemTypeKey, Project.MSG_VERBOSE); } else { config = new FTPClientConfig(); task.log("custom config: system key = default (UNIX)", Project.MSG_VERBOSE); } String defaultDateFormatConfig = task.getDefaultDateFormatConfig(); if (defaultDateFormatConfig != null) { config.setDefaultDateFormatStr(defaultDateFormatConfig); task.log("custom config: default date format = " + defaultDateFormatConfig, Project.MSG_VERBOSE); } String recentDateFormatConfig = task.getRecentDateFormatConfig(); if (recentDateFormatConfig != null) { config.setRecentDateFormatStr(recentDateFormatConfig); task.log("custom config: recent date format = " + recentDateFormatConfig, Project.MSG_VERBOSE); } String serverLanguageCodeConfig = task.getServerLanguageCodeConfig(); if (serverLanguageCodeConfig != null) { if (!"".equals(serverLanguageCodeConfig) && !FTPClientConfig.getSupportedLanguageCodes().contains(serverLanguageCodeConfig)) { throw new BuildException("unsupported language code" + serverLanguageCodeConfig); } config.setServerLanguageCode(serverLanguageCodeConfig); task.log("custom config: server language code = " + serverLanguageCodeConfig, Project.MSG_VERBOSE); } String serverTimeZoneConfig = task.getServerTimeZoneConfig(); if (serverTimeZoneConfig != null) { config.setServerTimeZoneId(serverTimeZoneConfig); task.log("custom config: server time zone ID = " + serverTimeZoneConfig, Project.MSG_VERBOSE); } String shortMonthNamesConfig = task.getShortMonthNamesConfig(); if (shortMonthNamesConfig != null) { config.setShortMonthNames(shortMonthNamesConfig); task.log("custom config: short month names = " + shortMonthNamesConfig, Project.MSG_VERBOSE); } client.configure(config); return client; }