ftp - Java FTPClient does not transfer the whole file -


i wrote java class downloading files ftp server. seem fine, when check size of files bit smaller original files.

any idea why happens?

import java.io.fileoutputstream; import java.io.bufferedoutputstream; import java.io.outputstream; import java.io.ioexception;  import org.apache.commons.net.ftp.ftp; import org.apache.commons.net.ftp.ftpclient; import org.apache.commons.net.ftp.ftpfile;  import java.io.ioexception;  public class downloader {     public static void main(string[] args) {         string server = "ftp.example.gov";         int port = 21;         string user = "anonymous";         string pass = "anonymous";         ftpclient ftpclient = new ftpclient();          try {             ftpclient.connect(server, port);             ftpclient.login(user, pass);             ftpclient.cwd("dir1/dir2/gz");              ftpfile[] files = ftpclient.listfiles();              (ftpfile file : files) {                 string downloadfile = "/home/andrej/documents/" + file.getname();                 outputstream output = new bufferedoutputstream(new fileoutputstream(downloadfile));                 boolean success = ftpclient.retrievefile(file.getname(), output);                 output.close();                 if (success) {                     system.out.println(file.getname());                 }             }          } catch (ioexception e) {             system.out.println("error: " + e.getmessage());             e.printstacktrace();         } {             try {                 if (ftpclient.isconnected()) {                     ftpclient.logout();                     ftpclient.disconnect();                 }             } catch (ioexception e) {                 e.printstacktrace();             }          }     } } 

try download in binary mode, difference might due differences in carriage returns between 2 servers. if server windows, have crlf, while linux have new line. ftp in ascii mode conversion automatically you.

when compare both file, identical textwise ? if so, don't think have worry it.


Comments