Howto do a simple ftp get file on Android

Whew! I finally got it going. I gave up on the simple way that works in webOS and WPF/C# where you can just do a ftp:://… you have to use the FTPClient package.

After fixing the library access (Project | Properties | Java Build Path | Libraries | Add JARs…) I fiddled with the calls until it started working. Here’s the sequence of my FTPClient calls. It wouldn’t work until I set it in passive mode.

  mFTPClient = new FTPClient();
  mFTPClient.connect("tgftp.nws.noaa.gov");      
  mFTPClient.login("anonymous","nobody");
  mFTPClient.enterLocalPassiveMode();
  mFTPClient.changeWorkingDirectory("/data/forecasts/taf/stations");
  InputStream inStream = mFTPClient.retrieveFileStream("KABQ.TXT");
  InputStreamReader isr = new InputStreamReader(inStream, "UTF8");

Leave a Comment