Hello, I'm a new member of the community, I hope that you can help me with my issue. I'm trying to retrieve a file from a ftp server (located on my notebook), but I can't do it and I can't figure out why. I can access to the server, list the files on it but when I try to download a test file it just doesn't do it. I'm using commons-net 2.2 library. Here's the code:
import org.apache.commons.net.ftp.FTPClient; import java.io.*; public class ClientFtp { /** * @param args */ public static void main(String[] args) { String localpath = "/Users/usr_name/Desktop"; String remotepath = "/Users/usr_name/ftpfile"; FTPClient client = new FTPClient(); FileOutputStream fout = null; try{ fout = new FileOutputStream(localpath + "newfile.txt"); client.connect("192.168.1.6", 21); System.out.println(client.getReplyString()); client.login("user", "pwd"); System.out.println(client.getReplyString()); if (client.retrieveFile(remotepath + "testfile.txt", fout)) System.out.println("download complete"); else System.out.println("error while downloading"); fout.flush(); fout.close(); client.disconnect(); } catch (IOException e){ System.out.println(e.toString()); } } }
Can someone give me a hint on what's wrong?
Thanks