开发者

FTPClient(org.apache.commons.net.ftp.FTPClient) is not able to retrieve large xml file

I have three different sizes of files in my ftp location with 2KB, 76KB and 216MB. I have to process these files one by one, I am able to retrieve the first two fil开发者_JAVA百科es easily using the retrieveFileStream(FILE_NAME_HERE) but when it comes to process the third file, it takes forever (my application keeps hanging) with no results. I have to get the files as input stream and make jaxb object out of them later. This is the utility method which I am using to get the input stream:

public InputStream convertToInputStream(FTPFile file) throws IOException{
        if(file!=null){
            InputStream is=ftp.retrieveFileStream(file.getName());

            ftp.completePendingCommand();
            return is;

        }

        return null;

Can you please point what I am doing wrong here?


This is probably to late to help you (might help someone else though) but when I had a similar problem (both upload and download) I was able to resolve it by setting the buffer size, setBufferSize(), after connecting see the code snippet below. This took my uploads from 12min for a 240MB file to 18seconds with a similar improvement on the download.

I have the BUFFER_SIZE set to 32768 but 8192 worked almost as well, especially for sub 50MB files after which there was a slight improvement with the larger size.

if (this.ftpClient.isConnected())
{
    this.ftpClient.enterLocalPassiveMode();
    this.ftpClient.setBufferSize(BUFFER_SIZE);
    try
    {
        this.ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
    }
    catch (IOException e)
    {
        log.error(e.getLocalizedMessage(), e);
        throw Throwables.propagate(e);
    }
}

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜