Java Code Examples for org.apache.commons.net.ftp.FTPClientConfig#setServerTimeZoneId()

The following examples show how to use org.apache.commons.net.ftp.FTPClientConfig#setServerTimeZoneId() . 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: FtpUtil.java    From AndroidRobot with Apache License 2.0 5 votes vote down vote up
/**
 * @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 2
Source File: FtpClientFactory.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
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);
    }
}