Problem with FTP download using jakarta commons
Hello all,
I am using Jakarta-commons for download of a file from an FTPserver to the local machine.
I am able to connect to the server properly...also a file with the name required is also being created in the local folder.
The problem comes here...the file created is of 0 bytes, no matter what is there in the file to be downloaded.
Can anyone help me on this...i have been searching for the bug in the FTPClient.class in the commons-net.1.4.1 jar of jakarta, but...no use..
will be waiting for help...
please give more code, especially the one linked to the download process
there is this class jakartaftpwrapper that extends ftpclient...
the code goes like this for downoad in this java file:
public boolean downloadFile (String serverFile, String localFile)
throws IOException, FTPConnectionClosedException {
FileOutputStream out = new FileOutputStream(localFile);
System.out.println("Local file path"+out.getChannel());
boolean result = retrieveFile(serverFile, out);
System.out.println("Result is "+result);
out.close();
return result;
}
this method downloadFile() is being called from another .java where the main method is written...the code in that file goes like this:
public static void main(String[] args) {
// TODO Auto-generated method stub
JakartaFtpWrapper jfw = new JakartaFtpWrapper();
try {
jfw.connectAndLogin("127.0.0.1","rajesh","rajesh");
System.out.println(jfw.getSystemName());
System.out.println(jfw.getRemotePort());
System.out.println(jfw.isConnected());
jfw.downloadFile("C:\\ftpsite\\load\\hello.txt","C:\\ftpsite\\download\\hi.txt");
jfw.disconnect();
} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Now...in the hello.txt there is some stuff....which is not being copied into the hi.txt when it is being created...
hope this explains you...
if the file is 0byte in length when you download it, that means the ftpclient couldn't access it ; i never used jakarta ftpclient class, but i think the way you give the serverFile url might be wrong
you say to the client: "hey, download me the file C:\\ftpsite\\load\\hello.txt"
first of all, this unique statement means you have a c:\\ access on the ftp, which is a bit unusual ; you might make sure you have such an access at first
actually, if i were to write your request, i would say:
"hey, put me into the C:\\ftpsite\\load directory!" (using changeworkingdirectory)
and then i would say:
"hey, give me hello.txt !"
according to me, the problem comes from your ftp approach ; you may give a try to this solution
As you have suggested, i have added these lines of code
jfw.changeWorkingDirectory("C:\\ftpsite\\load\\");
jfw.downloadFile("hello.txt","C:\\ftpsite\\download\\hi.txt");
still...there is no change in the output!
when i tried to print the value of "result" of the "downloadFile" method, in the on console, it is "false"...here is the problem with retreiving the file!
it may come from the fact ftp dirs are usually using / and not \you may try to list the files of the working directory (with println), to see if you're REALLY in the directory before requesting the file
hey...thanku for that!it is working...but, now...its a new problem...the text being written into is not matching with the original one...why is it so?do i need to do any conversions before using that file?
jahswqddfvejgejwhile the above is the text given in the hello.txt...udfhuahsdsadfhidasdfasdfuhasidfhasdfhsiaisadfasdfhioashdfasdfhioasikss:wid being printed in hi.txt?
that's a bit weird!!you should launch a new thread about this, since it's a new problemi think i will be helpless on that one, i just don't see what ***** here lol
thought you might give me another good one!anyway...thanks a bunch!