Go Down

Topic: Uploading file from SD card to remote server? (Read 14778 times) previous topic - next topic

cedric2

#45
Mar 22, 2012, 11:34 pm Last Edit: Mar 22, 2012, 11:45 pm by cedric2 Reason: 1
Just a few ROM octed to safe the network :-)
Code: [Select]

byte buf[64];
byte n;
     while ((n = dclient.read(buf, sizeof(buf))) > 0)
               f.write(buf,n);

It's 50 times faster... and probably more with latency network

Bonjour Tim et Cedric,

Just reading with interest your work on implementing ftp.
I would like to put ftp into my project so I can transfer stored files on SD card, html and log files.
I want to be able to have ftp access to the Arduino Mega from where ever I am.

What is the latest code that I should now be looking at to do this, I don't yet see a standard library for it.

Santé
rockwallaby

SurferTim

I added my latest FTP code to the playground here:
http://www.arduino.cc/playground/Code/FTP

Cool SurferTim,
Me goes and have a looksie as me thinks ftp will be just what me needs.
I have Webduino library as part of my project, I am hoping the possibility of problems will be lowwwww.

Thanks again very much for your efforts with it.

MrGlasspoole

Hi,

i really wonder that this is the only thing i can find on FTP.
I did spend a lot of money for hardware for the thing i want to build.
I'm learning now and reading sensors and saving to SD works.
But i never was thinking that the uploading stuff through FTP will be a problem.
I mean there is so many Arduino<->Internet stuff out there that a thought this
is something basic and will not be a problem.

Now i found out that it looks like nobody uses FTP.
Everybody is sending his stuff through HTML POST and is always connected to a server.
I'm not really understanding why. If your Internet connection is down your stuff
is not recorded, or if your router is broken, and so on...
Also sending everything in a URL is not really good practice.

I'm new to the Arduino programming stuff but i did some commercial websites
and know all the CMS- Shop systems, HTML, PHP, SQL, Javascript...

So my idea was to save my Arduino stuff to SD (csv), upload it to the server
and let php write it into the database. So if the internet connection is down
my Arduino still can record the data. And the idea was to make two files cause
you can't log data and upload the file ad the same time.

So Arduino logs data to csv1 and after some time to csv2. When logging to csv2 starts - csv1 gets uploaded
and vice versa.

So now i try to get this FTP code to work with sdfat and get rid of the download stuff but
i don't get it.
One drawback is that the password is send in plain so explicit FTPS would be cool.

SurferTim

Quote
Now i found out that it looks like nobody uses FTP.

Now I have been demoted to "nobody"?
http://playground.arduino.cc/Code/FTP

At least in Puerto Vallarta when I would help some poor boat belonging to an errant owner, I was "somebody", as in "Hey!! Somebody moved my boat and kept it from being run over and sunk by that cruise ship!".

MrGlasspoole

Sorry if my English sentences not always have the right meaning.
Nobody was meant more like: scarcely anybody...

Sure here i found something about FTP. But so many people do web stuff with Arduino
and then there is so few FTP usage?

And yes, your code is what i trying to modify since 3 days and not even
can it make compile without errors.

SurferTim

I went to the playground, went to the FTP section, clicked on the "get code" link to get a text version of the code, copied and pasted that into IDE v1.0.2. It compiled without modifications.

MrGlasspoole

You did nor read my first posting here in this thread? :(
Quote
So now i try to get this FTP code to work with sdfat and get rid of the download stuff but
i don't get it.

Sure the original code works.

SurferTim

#54
Dec 15, 2012, 07:48 pm Last Edit: Dec 15, 2012, 07:52 pm by SurferTim Reason: 1
I'm not certain what you want to do. If it works the way it is, why do you want to change it? The way that code is written, it either uploads to the server, or downloads from the server, depending on FTPWRITE. Set like this, it compiles as a download (upload from client end) from the SD to the FTP server.
Code: [Select]
#define FTPWRITE

If you compile with that define commented out like this, it only uploads (download from client end) from the server to the SD.
Code: [Select]
// #define FTPWRITE

Only the code needed for that function is included in the compiled version.

MrGlasspoole

I need to change it because all my other stuff uses sdfat and not the Arduino SD library.

SurferTim

I don't use sdfat. That is a subject best handled in the Storage section, one more down. That is where fat16lib hangs out. Post your problem there with a link to the FTP code, and maybe fat16lib (or someone experienced with sdfat) will be able to translate that for you.

richardkhoo

Hello SurferTim/Anybody

I intend to use your FTP code. Can you please explain which part of your code actually prints out the response from FTP server to Serial monitor? I assume is the eRcv() function, am I correct? If so, can you please explain how does it work? (the function)

I tried a file from my SD, however, the serial monitor didn't show the TRANSFERING response from the server, so I would like to understand more. Please help. Thanks

SurferTim

You can display it if you feel you need that. It does for the upload from FTP to SD, but not the other way. You can modify the code to display it if you want. I added it below for you.
Code: [Select]
#ifdef FTPWRITE
  Serial.println(F("Writing"));

  byte clientBuf[64];
  int clientCount = 0;

  while(fh.available())
  {
    clientBuf[clientCount] = fh.read();
// add this line
    Serial.write(clientBuf[clientCount]);
    clientCount++;


    if(clientCount > 63)
    {
      dclient.write(clientBuf,64);
      clientCount = 0;
    }
  }

  if(clientCount > 0) dclient.write(clientBuf,clientCount);

#else
  while(dclient.connected())
  {
    while(dclient.available())
    {
      char c = dclient.read();
      fh.write(c);     
// this already displays the upload file
      Serial.write(c);
    }
  }
#endif


richardkhoo

Thanks for the code, SurferTim. Would you mind to explain:

1. the purpose of variable for clientBuf[clientCount] for the SD card read?
2. why there is a if statement with condition of clientCount>63? What does the 63 represent?

One more specfic question with your exisiting FTP code:
- can you explain what is the objective of function eRcv() after client.print?

Thanks!

Go Up