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

查看:99
本文介绍了使用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:/文档和设置/测试

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天全站免登陆