使用 Apache Commons Net 下载后 FTP 文件损坏 [英] FTP file corrupt after download with Apache Commons Net

查看:39
本文介绍了使用 Apache Commons Net 下载后 FTP 文件损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由此下载的文件,大小几乎相同,但某些行不同.每个答案都指向二进制文件类型.但这无济于事.有人知道这个问题(传输 PDF)吗?

The files downloaded by this, are nearly the same size but differ in some lines. Every answer points to binary file type. But this won't help. Got anybody an idea for the problem (transferring PDF)?

FTPClient ftpClient = new FTPClient();
OutputStream outputStream = null;
boolean resultOk = true;

try {
    ftpClient.connect(host, port);
    ftpClient.enterLocalPassiveMode();
    ftpClient.setFileTransferMode(FTP.COMPRESSED_TRANSFER_MODE);
    ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
    if (showMessages) {
        System.out.println(ftpClient.getReplyString());
    }
    resultOk &= ftpClient.login(usr, pwd);
    if (showMessages) {
        System.out.println(ftpClient.getReplyString());
    }

    outputStream = new FileOutputStream(localResultFile);
    resultOk &= ftpClient.retrieveFile(remoteSourceFile, outputStream);
    outputStream.flush();
    outputStream.close();

    if (showMessages) {
        System.out.println(ftpClient.getReplyString());
    }
    if (resultOk == true) {
        resultOk &= ftpClient.deleteFile(remoteSourceFile);
    }

    resultOk &= ftpClient.logout();
    if (showMessages) {
        System.out.println(ftpClient.getReplyString());
    }
} finally {

    ftpClient.disconnect();
}

推荐答案

使用包含空格的非转义路径时似乎会发生这种情况.例如.C:/Documents and Settings/测试

It seems to happen when using unescaped paths that contain spaces. E.g. C:/Documents and Settings/test

现在通过对空格使用转义路径解决了这个问题.感谢您的帮助

Got it solved now by using a escaped path for the spaces. Thanks for your help

这篇关于使用 Apache Commons Net 下载后 FTP 文件损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆