Download file from FTP server?

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?

void setup(){

  PImage img = loadImage("");


Thank you in advance!


If you look at the source code for loadImage(), it looks like this (I deleted some lines for clarity):

// processing/core/src/processing/core/

  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.
    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 :

// processing/core/src/processing/core/

  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)
            int response = httpConn.getResponseCode();
            // Default won't follow HTTP -> HTTPS redirects for security reasons
            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 :

you can use external libraries like edtFTPj or ftp4j.

1 Like

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

1 Like

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…

1 Like