org.apache.commons.net.ftp.FTPClientConfig Java Examples
The following examples show how to use
org.apache.commons.net.ftp.FTPClientConfig.
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: FtpServiceImpl.java From zfile with MIT License | 6 votes |
@SneakyThrows(IOException.class) @Override public void init(Integer driveId) { this.driveId = driveId; Map<String, StorageConfig> stringStorageConfigMap = storageConfigService.selectStorageConfigMapByDriveId(driveId); host = stringStorageConfigMap.get(StorageConfigConstant.HOST_KEY).getValue(); port = stringStorageConfigMap.get(StorageConfigConstant.PORT_KEY).getValue(); username = stringStorageConfigMap.get(StorageConfigConstant.USERNAME_KEY).getValue(); password = stringStorageConfigMap.get(StorageConfigConstant.PASSWORD_KEY).getValue(); domain = stringStorageConfigMap.get(StorageConfigConstant.DOMAIN_KEY).getValue(); super.basePath = stringStorageConfigMap.get(StorageConfigConstant.BASE_PATH).getValue(); if (Objects.isNull(host) || Objects.isNull(port)) { isInitialized = false; } else { ftp = new Ftp(host, Integer.parseInt(port), username, password, StandardCharsets.UTF_8); ftp.getClient().configure(new FTPClientConfig(FTPClientConfig.SYST_UNIX)); ftp.getClient().type(FTP.BINARY_FILE_TYPE); testConnection(); isInitialized = true; } }
Example #2
Source File: FtpConnection.java From xian with Apache License 2.0 | 6 votes |
FTPClient connect(String path, String addr, int port, String username, String password) throws Exception { FTPClient ftp = new FTPClient(); int reply; ftp.connect(addr, port); ftp.login(username, password); ftp.configure(new FTPClientConfig(ftp.getSystemType())); ftp.setControlEncoding("UTF-8"); ftp.setFileType(FTPClient.BINARY_FILE_TYPE); reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); return null; } ftp.changeWorkingDirectory(path); return ftp; }
Example #3
Source File: FTPListService.java From cyberduck with GNU General Public License v3.0 | 6 votes |
public FTPListService(final FTPSession session, final String system, final TimeZone zone) { this.session = session; // Directory listing parser depending on response for SYST command final CompositeFileEntryParser parser = new FTPParserSelector().getParser(system, zone); this.implementations.put(Command.list, new FTPDefaultListService(session, parser, Command.list)); if(PreferencesFactory.get().getBoolean("ftp.command.stat")) { if(StringUtils.isNotBlank(system)) { if(!system.toUpperCase(Locale.ROOT).contains(FTPClientConfig.SYST_NT)) { // Workaround for #5572. this.implementations.put(Command.stat, new FTPStatListService(session, parser)); } } else { this.implementations.put(Command.stat, new FTPStatListService(session, parser)); } } if(PreferencesFactory.get().getBoolean("ftp.command.mlsd")) { this.implementations.put(Command.mlsd, new FTPMlsdListService(session)); } if(PreferencesFactory.get().getBoolean("ftp.command.lista")) { this.implementations.put(Command.lista, new FTPDefaultListService(session, parser, Command.lista)); } }
Example #4
Source File: FTPClientFactory.java From springboot-ureport with Apache License 2.0 | 5 votes |
/** * 创建一个FTPClient对象 */ @Override public FTPClient makeObject() throws Exception { FTPClient ftpClient = new FTPClient(); // ftpClient.setConnectTimeout(clientTimeout); ftpClient.connect(properties.getHostname(), properties.getPort()); int replyCode = ftpClient.getReplyCode(); if(!FTPReply.isPositiveCompletion(replyCode)){ ftpClient.disconnect(); log.warn("FTPServer 拒绝连接 !"); return null; } boolean login = ftpClient.login(properties.getUsername(), properties.getPassword()); if(!login){ throw new FTPConnectionClosedException("FTPServer 登录失败!"); } // ftpClient.setControlEncoding("UTF-8"); FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_NT); conf.setServerLanguageCode("zh"); ftpClient.configure(conf); //ftpClient.setFileType(fileType); // ftpClient.setBufferSize(1024); // ftpClient.setControlEncoding(encoding); // if (passiveMode) { // ftpClient.enterLocalPassiveMode(); // } return ftpClient; }
Example #5
Source File: CompositeFileEntryParser.java From cyberduck with GNU General Public License v3.0 | 5 votes |
@Override public void configure(final FTPClientConfig config) { for(FTPFileEntryParser parser : parsers) { if(parser instanceof Configurable) { ((Configurable) parser).configure(config); } } }
Example #6
Source File: CommonUnixFTPEntryParser.java From cyberduck with GNU General Public License v3.0 | 5 votes |
/** * Defines a default configuration to be used when this class is * instantiated without a {@link FTPClientConfig FTPClientConfig} * parameter being specified. * * @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; }
Example #7
Source File: FTPParserFactory.java From cyberduck with GNU General Public License v3.0 | 5 votes |
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); } } // Defaulting to UNIX parser return this.createUnixFTPEntryParser(timezone); }
Example #8
Source File: FTPParserFactory.java From cyberduck with GNU General Public License v3.0 | 5 votes |
private CompositeFileEntryParser createNetwareFTPEntryParser(final TimeZone timezone) { return new CompositeFileEntryParser(Arrays.asList( new NetwareFTPEntryParser() { @Override protected FTPClientConfig getDefaultConfiguration() { final FTPClientConfig config = super.getDefaultConfiguration(); config.setServerTimeZoneId(timezone.getID()); return config; } }, this.createUnixFTPEntryParser(timezone) )); }
Example #9
Source File: FTPParserFactory.java From cyberduck with GNU General Public License v3.0 | 5 votes |
private CompositeFileEntryParser createNTFTPEntryParser(final TimeZone timezone) { return new CompositeFileEntryParser(Arrays.asList( new NTFTPEntryParser() { @Override public FTPClientConfig getDefaultConfiguration() { final FTPClientConfig config = super.getDefaultConfiguration(); config.setServerTimeZoneId(timezone.getID()); return config; } }, this.createUnixFTPEntryParser(timezone) )); }
Example #10
Source File: FTPParserFactory.java From cyberduck with GNU General Public License v3.0 | 5 votes |
private CompositeFileEntryParser createOS2FTPEntryParser(final TimeZone timezone) { return new CompositeFileEntryParser(Collections.singletonList( new OS2FTPEntryParser() { @Override protected FTPClientConfig getDefaultConfiguration() { final FTPClientConfig config = super.getDefaultConfiguration(); config.setServerTimeZoneId(timezone.getID()); return config; } } )); }
Example #11
Source File: FTPParserFactory.java From cyberduck with GNU General Public License v3.0 | 5 votes |
private CompositeFileEntryParser createOS400FTPEntryParser(final TimeZone timezone) { return new CompositeFileEntryParser(Arrays.asList( new OS400FTPEntryParser() { @Override protected FTPClientConfig getDefaultConfiguration() { final FTPClientConfig config = super.getDefaultConfiguration(); config.setServerTimeZoneId(timezone.getID()); return config; } }, this.createUnixFTPEntryParser(timezone) )); }
Example #12
Source File: FTPParserFactory.java From cyberduck with GNU General Public License v3.0 | 5 votes |
private CompositeFileEntryParser createMVSEntryParser(final TimeZone timezone) { return new CompositeFileEntryParser(Collections.singletonList( new MVSFTPEntryParser() { @Override protected FTPClientConfig getDefaultConfiguration() { final FTPClientConfig config = super.getDefaultConfiguration(); config.setServerTimeZoneId(timezone.getID()); return config; } } )); }
Example #13
Source File: FtpUtil.java From AndroidRobot with Apache License 2.0 | 5 votes |
/** * @return 判断是否登入成功 * */ public boolean ftpLogin() { boolean isLogin = false; FTPClientConfig ftpClientConfig = new FTPClientConfig(); ftpClientConfig.setServerTimeZoneId(TimeZone.getDefault().getID()); this.ftpClient.setControlEncoding("GBK"); this.ftpClient.configure(ftpClientConfig); try { if (this.intPort > 0) { this.ftpClient.connect(this.strIp, this.intPort); } else { this.ftpClient.connect(this.strIp); } // FTP服务器连接回答 int reply = this.ftpClient.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { this.ftpClient.disconnect(); System.out.println("登录FTP服务失败!"); return isLogin; } this.ftpClient.login(this.user, this.password); // 设置传输协议 this.ftpClient.enterLocalPassiveMode(); this.ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); System.out.println("恭喜" + this.user + "成功登陆FTP服务器"); //logger.info("恭喜" + this.user + "成功登陆FTP服务器"); isLogin = true; } catch (Exception e) { e.printStackTrace(); System.out.println(this.user + "登录FTP服务失败!" + e.getMessage()); //logger.error(this.user + "登录FTP服务失败!" + e.getMessage()); } this.ftpClient.setBufferSize(1024 * 2); this.ftpClient.setDataTimeout(30 * 1000); return isLogin; }
Example #14
Source File: FtpClientFactory.java From commons-vfs with Apache License 2.0 | 5 votes |
private void configureClient(final FileSystemOptions fileSystemOptions, final C client) { final String key = builder.getEntryParser(fileSystemOptions); if (key != null) { final FTPClientConfig config = new FTPClientConfig(key); final String serverLanguageCode = builder.getServerLanguageCode(fileSystemOptions); if (serverLanguageCode != null) { config.setServerLanguageCode(serverLanguageCode); } final String defaultDateFormat = builder.getDefaultDateFormat(fileSystemOptions); if (defaultDateFormat != null) { config.setDefaultDateFormatStr(defaultDateFormat); } final String recentDateFormat = builder.getRecentDateFormat(fileSystemOptions); if (recentDateFormat != null) { config.setRecentDateFormatStr(recentDateFormat); } final String serverTimeZoneId = builder.getServerTimeZoneId(fileSystemOptions); if (serverTimeZoneId != null) { config.setServerTimeZoneId(serverTimeZoneId); } final String[] shortMonthNames = builder.getShortMonthNames(fileSystemOptions); if (shortMonthNames != null) { final StringBuilder shortMonthNamesStr = new StringBuilder(BUFSZ); for (final String shortMonthName : shortMonthNames) { if (shortMonthNamesStr.length() > 0) { shortMonthNamesStr.append("|"); } shortMonthNamesStr.append(shortMonthName); } config.setShortMonthNames(shortMonthNamesStr.toString()); } client.configure(config); } }
Example #15
Source File: FTPParserFactory.java From cyberduck with GNU General Public License v3.0 | 4 votes |
public CompositeFileEntryParser createFileEntryParser(final FTPClientConfig config) throws ParserInitializationException { return this.createFileEntryParser(config.getServerSystemKey(), TimeZone.getTimeZone(config.getServerTimeZoneId())); }