FTPClient 路径中文获取不到数据

//ftp构造
public FTPUtil(String hostname, int port, String userName, String password) {
    ftpClient = new FTPClient();
    this.hostname = hostname;
    this.port = port;
    this.userName = userName;
    this.password = password;
}
//ftp连接
public boolean connectServer() throws SocketException, IOException {
    ftpClient.connect(hostname, port);
    boolean isLogin = ftpClient.login(userName, password);
    boolean isSetFileType = ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
    ftpClient.cwd(rootNode);
    ftpClient.enterLocalPassiveMode();
    return isLogin && isSetFileType;

}

ftp下载文件

public String downloadFileFromFTP(String ftpFilePath) {
    InputStream is = null;
    byte[] data = null;
    ByteArrayOutputStream swapStream = null;
    try {
        // 获取ftp上的文件流
        is = ftpClient.retrieveFileStream(new String(ftpFilePath.getBytes("GBK"),"ISO-8859-1"));
        swapStream = new ByteArrayOutputStream();
        byte[] buff = new byte[1024];
        int rev = 0;
        while ((rev = is.read(buff, 0, buff.length)) > 0) {
            swapStream.write(buff, 0, rev);
        }
        data = swapStream.toByteArray();
        ftpClient.completePendingCommand();
        logger.info("FTP文件下载成功!");
    } catch (Exception e) {
        logger.error("FTP文件下载失败!", e);
    } finally {
        try {
            if (is != null) {
                is.close();
            }
            if (swapStream != null) {
                swapStream.close();
            }
        } catch (IOException e) {
            logger.info("关闭流发生异常_"+e);
        }
    }
    return Base64.encodeBase64String(data);

//上传文件

public boolean uploadFile(File localFile, String remoteFile) throws IOException {
    FileInputStream is = null;
    try {
        is = new FileInputStream(localFile);
        logger.info("FileInputStream file" + is);
        return ftpClient.appendFile(remoteFile, is);
    } finally {
        try {
            if (is != null) {
                is.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值