title: Howto do a simple ftp get file on Android
body: <p>I can't find an example of a simple FTP access of a file anywhere, and the FTPClient class (which a couple of examples use) doesn't appear in the Android Class Index. I've got http access working, but how do I do a simple FTP get? All I want to do is download (for example):
  <a href="ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/KABQ.TXT" rel="nofollow noreferrer">ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/KABQ.TXT</a>
  It shouldn't require login, change directory, etc.
  Just giving that URL to the http access methods don't seem to work.</p>
  
  <p>This is similar to the question at:
  <a href="https://stackoverflow.com/questions/7009531/unable-to-read-file-from-ftp-in-android">unable to read file from ftp in android?</a></p>
  
  <p>I tried a simple:</p>
  
  <pre><code>  StringBuilder response = new StringBuilder();
    URLConnection ftpConn;
    try {
    URL netUrl = new URL("ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/KABQ.TXT");
    ftpConn = netUrl.openConnection();
    BufferedInputStream bufRd = new BufferedInputStream(ftpConn.getInputStream());
    int temp;
    while ((temp = bufRd.read()) != -1) {
        response.append(temp);
    }
    bufRd.close();
    } catch (Exception e) {
        return "Failure";
    }
  </code></pre>
  
  <p>but it gets an exception on getInputStream: 
  Unable to connect to server: Unable to configure data port</p>
  
  <p>Also, there must be a more intelligent way to pull the data out of the stream buffer than byte-by-byte, isn't there? I can't find that either.</p>
  
  <p>Lastly, I need to do both http and ftp access, is there any reason not to use URLConnection for both access types? or is it better to use HttpConnection for http and URLConnection for ftp?</p>
  
  <p>Thanks!</p>