# Download file from FTP server?

**URL:** <https://discourse.processing.org/t/download-file-from-ftp-server/22651>\
**Category:** Coding Questions\
**Created:** [July 16, 2020, 3:32am UTC](https://discourse.processing.org/t/download-file-from-ftp-server/22651 "2020-07-16T03:32:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jetjaguar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jetjaguar/32/1370_2.png) [@jetjaguar](https://discourse.processing.org/u/jetjaguar)\
**Post date:** [July 16, 2020, 3:32am UTC](https://discourse.processing.org/t/download-file-from-ftp-server/22651/1 "2020-07-16T03:32:29Z")

</div>

I feel like I’m missing something simple here.

I just want to download and then display an image file from a remote, public FTP server. When I try to do so I get “The file xxx is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable. NullPointerException.”

Is this a server settings issue I cannot get around with Processing, or am I missing a step?

```auto
void setup(){
  size(400,400);

  PImage img = loadImage("ftp://public.sos.noaa.gov/rt/true_color/4096/TRUE.daily.20200713.color.png");
  image(img,400,400);

}

```

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [July 17, 2020, 1:32pm UTC](https://discourse.processing.org/t/download-file-from-ftp-server/22651/2 "2020-07-17T13:32:59Z")

</div>

Hi,

If you look at the [source code](https://github.com/processing/processing) for `loadImage()`, it looks like this (I deleted some lines for clarity):

```auto
// processing/core/src/processing/core/PApplet.java

  public PImage loadImage(String filename, String extension) { //, Object params) {

    // For jpeg, gif, and png, load them using createImage(),
    // because the javax.imageio code was found to be much slower.
    // http://dev.processing.org/bugs/show_bug.cgi?id=392
    try {
      if (extension.equals("jpg") || extension.equals("jpeg") ||
          extension.equals("gif") || extension.equals("png") ||
          extension.equals("unknown")) {
        byte[] bytes = loadBytes(filename);

        //....

```

It uses the `loadBytes()` method to load the image :

```auto
// processing/core/src/processing/core/PApplet.java

  public byte[] loadBytes(String filename) {
    String lower = filename.toLowerCase();
    // If it's not a .gz file, then we might be able to uncompress it into
    // a fixed-size buffer, which should help speed because we won't have to
    // reallocate and resize the target array each time it gets full.
    if (!lower.endsWith(".gz")) {
      // If this looks like a URL, try to load it that way. Use the fact that
      // URL connections may have a content length header to size the array.
      if (filename.contains(":")) { // at least smells like URL
        InputStream input = null;
        try {
          URL url = new URL(filename);
          URLConnection conn = url.openConnection();
          int length = -1;

          if (conn instanceof HttpURLConnection) {
            HttpURLConnection httpConn = (HttpURLConnection) conn;
            // Will not handle a protocol change (see below)
            httpConn.setInstanceFollowRedirects(true);
            int response = httpConn.getResponseCode();
            // Default won't follow HTTP -> HTTPS redirects for security reasons
            // http://stackoverflow.com/a/1884427
            if (response >= 300 && response < 400) {
              String newLocation = httpConn.getHeaderField("Location");
              return loadBytes(newLocation);
            }

      // .....

```

Then the `loadBytes()` function uses the HTTP protocol to load the image from a URL. So FTP doesn’t work.

It seems that ftp is not yet supported with Processing but looking at this thread :

[https://forum.processing.org/beta/num\_1131152633.html](https://forum.processing.org/beta/num_1131152633.html)

you can use external libraries like [edtFTPj](https://enterprisedt.com/products/edtftpj/) or [ftp4j](http://www.sauronsoftware.it/projects/ftp4j/).

---

<div class="post-metadata">

**Author:** ![jetjaguar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jetjaguar/32/1370_2.png) [@jetjaguar](https://discourse.processing.org/u/jetjaguar)\
**Post date:** [July 17, 2020, 4:21pm UTC](https://discourse.processing.org/t/download-file-from-ftp-server/22651/3 "2020-07-17T16:21:54Z")

</div>

Oh interesting, thank you very much josephh. I will try those.

---

<div class="post-metadata">

**Author:** ![jetjaguar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jetjaguar/32/1370_2.png) [@jetjaguar](https://discourse.processing.org/u/jetjaguar)\
**Post date:** [July 17, 2020, 5:03pm UTC](https://discourse.processing.org/t/download-file-from-ftp-server/22651/4 "2020-07-17T17:03:05Z")

</div>

Hrm, it might be best to just use something like winscp to schedule automatic synchronization so that I can just point my sketch to a local folder…
