简体   繁体   中英

Downloading files from FTP

I'm trying to download files from FTP on Java using org.apache.commons.

try {
        OutputStream os = new FileOutputStream(downloadedFile);
        boolean success = this.client.retrieveFile(from, os);
        System.out.println("File transfer status is "+ Boolean.toString(success));
        os.close();
    } catch (IOException e) {
        System.err.println(e.getMessage());
    }

And files are downloading, but some images have error like Invalid image, another looks like that https://www.dropbox.com/s/faozfxzag5xrk5z/Screenshot_3.png

Any ideas? Thx

Try setting file type to binary, ie:

client.setFileType(FTP.BINARY_FILE_TYPE);

FTPClient has default settings to use FTP.ASCII_FILE_TYPE .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM