I'm writing a very simple FTPClient application using Apache's library.
All I do is download a jar file from a server. There is no exception, the application works fine when I run in on MacOS and as soon as I run the same code in Windows the downloaded file is smaller than the file on server. However, there is no exception and everything seems to be fine.
I'm going crazy, I'm using binary mode and the code is so simple I can't believe I've been stuck on it since yesterday!!!
Please help!
public boolean loadLatest(){
FTPClient ftp = new FTPClient();
try {
ftp.connect("server address");
ftp.setControlKeepAliveTimeout(300);
ftp.enterLocalPassiveMode();
String fu = "username";
ftp.login(fu, "password");
int reply = ftp.getReplyCode();
if (FTPReply.isPositiveCompletion(reply)) {
ftp.setFileTransferMode(FTP.BINARY_FILE_TYPE);
ftp.enterLocalPassiveMode();
FTPFilter filter = new FTPFilter();
FTPFile[] finfo = ftp.listFiles(".",filter);
if (finfo.length==0){
return false;
}
File currentJar = new File("sm.jar");
FileOutputStream output;
output = new FileOutputStream("sm.jar");
if (ftp.retrieveFile(finfo[0].getName(), output)==false){
System.out.println("Bad file!");
}
output.close();
ftp.logout();
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
Here is my code:
Thanks