zoukankan      html  css  js  c++  java
  • ftpclient 遇到的一些问题

    1. FTPFile[] files=ftpClient.listFiles(ftpDirectory); 没有数据

    public static boolean ftpLogin(String server,int port,String userName,String userPassword,FTPClient ftpClient){
    if(ftpClient==null){
    ftpClient= new FTPClient();
    }
    boolean isLogin = false;
    if(ftpClient!=null && ftpClient.isConnected()){
    isLogin=true;
    return isLogin;
    }
    ftpClient.setControlEncoding("GBK");
    try {
    if (port > 0) {
    ftpClient.connect(server, port);
    } else {
    ftpClient.connect(server);
    }
    // FTP服务器连接回答
    int reply = ftpClient.getReplyCode();
    if (!FTPReply.isPositiveCompletion(reply)) {
    ftpClient.disconnect();
    ToolUtils.logger.error("登录FTP服务失败!");
    return isLogin;
    }
    ftpClient.login(userName, userPassword);
    // 设置传输协议
    ftpClient.enterLocalPassiveMode();    //应该是这个,没有主动打开端口接收数据
    ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
    ToolUtils.logger.warn("恭喜" + userName + "成功登陆FTP服务器");
    isLogin = true;
    } catch (Exception e) {
    e.printStackTrace();
    ToolUtils.logger.error(userName + "登录FTP服务失败!" + e.getMessage());
    }
    ftpClient.setBufferSize(1024 * 2);
    ftpClient.setDataTimeout(30 * 1000);
    return isLogin;
    }

    2.中文乱码

    ftpClient.setControlEncoding("GBK");

    3.ftpClient.storeFile(new String(filename.getBytes("UTF-8"),"iso-8859-1"),is) ;无法写入内容

    3.1 ftpClient.changeWorkingDirectory(filepath);//必须写上一次目录 列:/a/a.txt  只写/a  或者/a/ 不然的话他把文件创建在根目录

    3.2 服务端防火墙拦截

    3.3 ftp文件没有赋予用户写入权限

    4.中文目录无法进去,修改内容

    ftpClient.storeFile(URLDecoder.decode(filename, "iso-8859-1"),is);//可以解决,一些人使用new string 进行转码,不能成功。具体原因我也不知道,求大神回答。

  • 相关阅读:
    70. 爬楼梯
    278. 第一个错误的版本
    88. 合并两个有序数组
    C++string与int的相互转换(使用C++11)
    108. 将有序数组转换为二叉搜索树
    102. 二叉树的层次遍历
    101. 对称二叉树
    98. 验证二叉搜索树
    ServletContext对象
    ServletConfig对象
  • 原文地址:https://www.cnblogs.com/cbdd/p/5842920.html
Copyright © 2011-2022 走看看