# Transfer jpg image from SD to FTP Server

**URL:** <https://community.particle.io/t/transfer-jpg-image-from-sd-to-ftp-server/41936>\
**Category:** Firmware\
**Created:** [May 21, 2018, 11:39pm UTC](https://community.particle.io/t/transfer-jpg-image-from-sd-to-ftp-server/41936 "2018-05-21T23:39:19Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jimmie](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@Jimmie](https://community.particle.io/u/Jimmie)\
**Post date:** [May 21, 2018, 11:39pm UTC](https://community.particle.io/t/transfer-jpg-image-from-sd-to-ftp-server/41936/1 "2018-05-21T23:39:19Z")

</div>

I am trying to transfer a very small image (jpg) from an SD card to an FTP server using a Photon. I can see that the FTP server does accept the connection, however, its log file shows the following error:

 ![Server](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/8/3/83c89869081c11cf0b0a29a37172de1134ecd2c7.jpg)

I am using the ParticleFtpClient library and the following code:

```
  myFile.open(filename, O_READ);
  int data;
  if (FTPclient.connect(FTPserver,FTPport)){
      while ((data = myFile.read()) >= 0){
          FTPclient.write(data);
      }
      FTPclient.stop();
  }

```

I have looked at a lot of weblinks but was unable to find out the problem and would appreciate some help.

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [May 21, 2018, 11:45pm UTC](https://community.particle.io/t/transfer-jpg-image-from-sd-to-ftp-server/41936/2 "2018-05-21T23:45:54Z")

</div>

@Jimmie, you defined `data` as a `int` which will read two bytes but only send one. You should define data as either a `char` or `uint8_t`. Try that to see if it works.

---

<div class="post-metadata">

**Author:** ![Jimmie](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@Jimmie](https://community.particle.io/u/Jimmie)\
**Post date:** [May 22, 2018, 12:13am UTC](https://community.particle.io/t/transfer-jpg-image-from-sd-to-ftp-server/41936/3 "2018-05-22T00:13:32Z")

</div>

Thank you @peekay123.

I tried unint8\_t, but it is giving “‘unint8\_t’ does not name a type”

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [May 22, 2018, 12:14am UTC](https://community.particle.io/t/transfer-jpg-image-from-sd-to-ftp-server/41936/4 "2018-05-22T00:14:49Z")

</div>

Oh blast! I misspelled it! It should be `uint8_t` !!!

---

<div class="post-metadata">

**Author:** ![Jimmie](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@Jimmie](https://community.particle.io/u/Jimmie)\
**Post date:** [May 22, 2018, 1:03am UTC](https://community.particle.io/t/transfer-jpg-image-from-sd-to-ftp-server/41936/5 "2018-05-22T01:03:45Z")

</div>

Thanks again @peekay123. I tried both but it did not work.

Sorry for wasting your time as I am realizing that the way I am doing it should not work. I am connecting to an FTP Server and then copying data to it without even telling it the name of the file to store it in.

The code above is not mine and was taken from [http://github.com/OUSmartInfrastructure/PhotonBikeSensor/tree/master/BikeSensorv3](http://github.com/OUSmartInfrastructure/PhotonBikeSensor/tree/master/BikeSensorv3)

When I tried using the ParticleFtpClient library, and using exact code like the example, I am getting the following error on open “no matching function for call to ‘particleftpclient::ParticleFtpClient::open(String&, int&, int&)’”

Also, the Web IDE goes wild and starts saying that it is missing .h files even though I checked that the Particle library is included along with its #include statement.

Is there anywhere a simple example that shows how to transfer a small jpg file from an SD card to an FTP server?

Thanks again.

---

<div class="post-metadata">

**Author:** ![RWB](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rwb/32/22599_2.png) [@RWB](https://community.particle.io/u/RWB)\
**Post date:** [May 22, 2018, 3:36am UTC](https://community.particle.io/t/transfer-jpg-image-from-sd-to-ftp-server/41936/6 "2018-05-22T03:36:35Z")

</div>

> [@Jimmie](#):
>
> Also, the Web IDE goes wild and starts saying that it is missing .h files even though I checked that the Particle library is included along with its #include statement.

We're trying to get images uploaded to an FTP server also.

Just having the #include statement added is not enough to pull the library into the IDE I think.

You may have to add these extra .h and .cpp tabs to the build IDE to get it to compile correctly so be sure to give that a try and report back.

---

<div class="post-metadata">

**Author:** ![Jimmie](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@Jimmie](https://community.particle.io/u/Jimmie)\
**Post date:** [May 22, 2018, 12:39pm UTC](https://community.particle.io/t/transfer-jpg-image-from-sd-to-ftp-server/41936/7 "2018-05-22T12:39:15Z")

</div>

I solved the problem by doing the following:

1. Do not use the built-in ParticleFtpClient library.

2. Import the ParticleFtpClient.cpp and ParticleFtpClient.h files  
(I do not know how to attach cpp and h files but I copied those from the Particle FTPFileSender library)

3. Use this code in the body

```cpp
        #include "ParticleFtpClient.h"
        #include <time.h>

        using namespace particleftpclient;

        String hostname = "server.dyndns.biz";
        String username = "test";
        String password = "test";
        int port = 21;

        int timeout = 5;

        ParticleFtpClient ftp = ParticleFtpClient();

```

1. Use the following code to download jpg file:

```cpp
      if (ftp.open(hostname, port, timeout)) {
      ftp.user(username);
      ftp.pass(password);
      ftp.type("I");
      ftp.stor(filename);
      while ((data = myFile.read()) >= 0) {
        ftp.data.write(data);
      }
      long int sendTime = millis() - now;
      ftp.data.flush();
      ftp.quit();
      //-------------------
           
      Particle.publish("Picture Sent", String(filename) + "," + String(sendTime));
      } 
      else
      {
        Particle.publish("FTP Error", "Cannot login");
      }

```

That said, I still think there is a bug in Web IDE for the following reasons:

1. Sometimes deleting a library deleting the library below it too.
2. When a new file is created and contents added, the same contents initlaly appear in both .cpp and .h.

---

<div class="post-metadata">

**Author:** ![RWB](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rwb/32/22599_2.png) [@RWB](https://community.particle.io/u/RWB)\
**Post date:** [May 22, 2018, 4:05pm UTC](https://community.particle.io/t/transfer-jpg-image-from-sd-to-ftp-server/41936/8 "2018-05-22T16:05:05Z")

</div>

@Jimmie Thanks for the tip!

@ScruffR in the part of the send data code shown below:

```cpp
while ((data = myFile.read()) &gt;= 0) {
        ftp.data.write(data);
      }
[/quote]

```

This pulls data from the SD card in chunks as you already know, but can’t we change this to pull the JPG image data chunks from the variable that holds the picture image that’s created in your uCAM3 library?

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [May 23, 2018, 5:03am UTC](https://community.particle.io/t/transfer-jpg-image-from-sd-to-ftp-server/41936/9 "2018-05-23T05:03:06Z")

</div>

You could try it.  
Currently I’ve set up a test server for @Vitesze to direct the TCP transfer to and wait for his reply.

---

<div class="post-metadata">

**Author:** ![RWB](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rwb/32/22599_2.png) [@RWB](https://community.particle.io/u/RWB)\
**Post date:** [May 23, 2018, 5:28am UTC](https://community.particle.io/t/transfer-jpg-image-from-sd-to-ftp-server/41936/10 "2018-05-23T05:28:35Z")

</div>

I could try but I have no idea how it would or could work which is why I asked you.

Conceptually, it seems the only difference is where the bytes are being pulled from, the Data stored on an SD card vs Data stored in a variable in the Photons memory. But maybe it’s not that simple? No idea really.

So how is FTP different than the Server setup you’re talking about for @Vitesze ? Is it an FTP server or something different?

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [May 23, 2018, 5:48am UTC](https://community.particle.io/t/transfer-jpg-image-from-sd-to-ftp-server/41936/11 "2018-05-23T05:48:16Z")

</div>

One “major” difference I’d anticipate is the timing with the rather slow uCam compared to an SD as source. This may or may not cause the FTP connection to time out and the code above does not take that into account (AFAICT).

The server I set up is running the NodeJS service and a rudimentary website to download the images.  
I can PM you the details too.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [May 23, 2018, 3:04pm UTC](https://community.particle.io/t/transfer-jpg-image-from-sd-to-ftp-server/41936/12 "2018-05-23T15:04:36Z")

</div>

@Jimmie, it should now be possible to import the library the normal way since 0.0.3 just got published by @jychuah

---

<div class="post-metadata">

**Author:** ![Jimmie](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@Jimmie](https://community.particle.io/u/Jimmie)\
**Post date:** [May 23, 2018, 9:23pm UTC](https://community.particle.io/t/transfer-jpg-image-from-sd-to-ftp-server/41936/13 "2018-05-23T21:23:36Z")

</div>

Thank you @ScruffR. Glad to hear of the update.

Thanks also to @jychuah.
