FTP upload to a dynamic ip address server?

Setup:
Arduino + Ethernet Sheild w/ SD card.
SD card has a file that it has log info on. file name is tp150826.txt

Objective: To upload the tp150826.txt file to my ftp server online, hosted by godaddy.com. My site is has a dynamic ip address. So it is always changing. but the host url never changes: eqrunner.com

I have tried using the stock ftp method from http://playground.arduino.cc/Code/FTP but that requires a static IP address. And this project that I am working on will result in the arduino being placed in a remote location that can not be accessed for as long as 3 months.

My mind is drawing a blank, then trying to go to what I know, and that is normal client (like FireFTP) to upload. Where I simply need the ftp host: eqrunner. Username: Arduino, Password: kittykat. (this is just demo and does not work) to accomplish the upload of the file.

Givin the above information. Is there a simple script that is out there that will allow you to simply upload a text file (8.3) format with out all the other bloat code.

Yes I have already been googling for the past 8 hours and just keep getting directed back to the sample playground code.

I use this for domain names. If the dns resolution fails, you won’t be able to upload or download code from the ftp server. I will leave it up to you what to add to the code if the dns fails.

// add this to includes
#include <Dns.h>

// in global area, change this
IPAddress server( 1, 2, 3, 4 );
// to this
IPAddress server;

// add these 
DNSClient dnClient;
// change this to a valid dns server IP
IPAddress myDns(1,2,3,4);

// then in setup
void setup()
{
  Serial.begin(115200);

  digitalWrite(10,HIGH);

  if(SD.begin(4) == 0)
  {
    Serial.println("SD init fail");          
  }

  // change to your dns server or use DHCP
  Ethernet.begin(mac, ip, myDns, gateway, subnet); 
  delay(2000);

  // start DNS client
  dnClient.begin(Ethernet.dnsServerIP());
  
  // resolve domain name to IP
  if(dnClient.getHostByName("www.myftpserver.com",server) == 1) {
    Serial.print(F("ftp = "));
    Serial.println(server);
  }
  else Serial.print(F("dns lookup failed"));

  Serial.println("Ready. Press f or r");
}

The client.connect() accepts a IP and a URL. Is that not enough ? the URL with domain name ?

My webhoster has a fixed single IP for ftp for my websites. Well, I guess there are many configurations possible.
SurferTim, I have not used "getHostByName" yet. I could use it to log every day the IP numbers of my sites :stuck_out_tongue:

eqrunning, if you upload data with ftp, and use HTML5 to show it on a webpage, then I am interested in the code. At this moment I upload a html file (generated with the sketch, not a file on the microSD) and I use a iframe for it. I choose this method, because I want to keep my router as closed as possible and I don't understand PHP.

Peter_n:
The client.connect() accepts a IP and a URL. Is that not enough ? the URL with domain name ?

It does, but performs a dns resolution every call to connect, once for the command channel, and again for the data channel. The IP call is much faster.

edit: If you do use the connect with a domain name, insure you change the return value evaluation.

// change this
  if (client.connect(server,21)) {
// to this
  if (client.connect(server,21) == 1) {

Peter_n,

My project in description sounds simple. It is an arduino that has analog glass temperature sensors. Every 60 seconds it writes the current temperature to the sd card for the given day. Ex: tp150828.txt. And writes it line by line…

On my website, I use PHP because you can insert external files to it. In my case. I have prebuilt PHP files for every day. And I use the php include function to insert the data from the text file that was uploaded. ( I hope I am explaining it well.)

For example. I use google charts. So I can have the text file write:

 [[hour,minute,second], sensor00, sensor01, sensor02, sensor03, sensor04, sensor05]

So I get a text file for today tp150826.txt (tp for temperature, Year, Month, Day).

[[03,19,01], 78.61 , -118.55 , 129.53 , 75.72 , null , 109.32 ],
[[03,20,01], 78.77 , -118.55 , 129.53 , 75.72 , null , 109.32 ],
[[03,21,01], 78.77 , -118.55 , 129.53 , 75.72 , null , 109.32 ],
[[03,22,01], 78.77 , -118.55 , 129.53 , 75.72 , null , 109.32 ],
[[03,23,01], 78.77 , -118.55 , 129.53 , 75.72 , null , 109.32 ],
[[03,24,01], 78.77 , -118.55 , 129.53 , 75.72 , null , 109.32 ],
[[03,25,01], 78.77 , -118.55 , 129.53 , 75.72 , null , 109.32 ],
[[03,26,01], 78.77 , -118.55 , 129.53 , 75.72 , null , 109.32 ],
[[03,27,01], 78.77 , -118.55 , 129.53 , 75.72 , null , 109.32 ],
[[03,28,01], 78.93 , -118.55 , 129.53 , 75.72 , null , 109.32 ],
[[03,29,01], 78.77 , -118.55 , 129.53 , 75.72 , null , 109.32 ],
[[03,30,01], 78.93 , -118.55 , 129.53 , 75.72 , null , 109.32 ],

Then on the PHP file. I have an include to input the file. PHP looks like this:

<html>
<head>
<title>ICE Tent 2015 Daily Report</title>
<link href="http://eqrunner.com/eqCSSscript.css" rel="stylesheet" type="text/css" />
<script type='text/javascript' src='http://www.google.com/jsapi'></script>
<script type="text/javascript">
    google.load('visualization', '1.1', {packages: ['line']});
    google.setOnLoadCallback(drawChart);

    function drawChart() {

      var data = new google.visualization.DataTable();
        // data.addColumn('datetime', 'Date');
        data.addColumn('timeofday', 'Time');
        data.addColumn('number', 'TempSensor');
        data.addColumn('number', 'LightSensor');
        data.addColumn('number', 'KnobSensor');
        data.addColumn('number', 'KnobSensor');
        data.addColumn('number', 'Sensor04');
        data.addColumn('number', 'Sensor05');
        data.addRows([

<?php include("temperature/tp150826.txt"); ?>

        ]);

      var options = {
        chart: {
          // title: 'ICE COLD Tent 2015',
          // subtitle: 'DATE OF DAY'
        },
        
        height: 800,


      };

      var chart = new google.charts.Line(document.getElementById('linechart_material'));

      chart.draw(data, options);


    }
  </script>
</head>
<body>
<p><a href="http://ice2015.eqrunner.com">ICE Tent 2015 Daily Report</a></p>
2015-08-27
<div id="linechart_material"></div>
<p align="right"><a href="http://eqrunner.com">Created and run by eqrunner inc</a></p> 
</body>
</html>

When you view it on the site server side. The PHP INCLUDE is replaced by the content of the file it is including. Thus getting a completed chart.

I want to have a local log file in addition to the log on my server.

This is what you see on the server:

<html>
<head>
<title>ICE Tent 2015 Daily Report</title>
<link href="http://eqrunner.com/eqCSSscript.css" rel="stylesheet" type="text/css" />
<script type='text/javascript' src='http://www.google.com/jsapi'></script>
<script type="text/javascript">
    google.load('visualization', '1.1', {packages: ['line']});
    google.setOnLoadCallback(drawChart);

    function drawChart() {

      var data = new google.visualization.DataTable();
        // data.addColumn('datetime', 'Date');
        data.addColumn('timeofday', 'Time');
        data.addColumn('number', 'TempSensor');
        data.addColumn('number', 'LightSensor');
        data.addColumn('number', 'KnobSensor');
        data.addColumn('number', 'KnobSensor');
        data.addColumn('number', 'Sensor04');
        data.addColumn('number', 'Sensor05');
        data.addRows([

[[03,19,01], 78.61 , -118.55 , 129.53 , 75.72 , null , 109.32 ],
[[03,20,01], 78.77 , -118.55 , 129.53 , 75.72 , null , 109.32 ],
[[03,21,01], 78.77 , -118.55 , 129.53 , 75.72 , null , 109.32 ],
[[03,22,01], 78.77 , -118.55 , 129.53 , 75.72 , null , 109.32 ],
[[03,23,01], 78.77 , -118.55 , 129.53 , 75.72 , null , 109.32 ],
[[03,24,01], 78.77 , -118.55 , 129.53 , 75.72 , null , 109.32 ],
[[03,25,01], 78.77 , -118.55 , 129.53 , 75.72 , null , 109.32 ],
[[03,26,01], 78.77 , -118.55 , 129.53 , 75.72 , null , 109.32 ],
[[03,27,01], 78.77 , -118.55 , 129.53 , 75.72 , null , 109.32 ],
[[03,28,01], 78.93 , -118.55 , 129.53 , 75.72 , null , 109.32 ],
[[03,29,01], 78.77 , -118.55 , 129.53 , 75.72 , null , 109.32 ],
[[03,30,01], 78.93 , -118.55 , 129.53 , 75.72 , null , 109.32 ],

        ]);

      var options = {
        chart: {
          // title: 'ICE COLD Tent 2015',
          // subtitle: 'DATE OF DAY'
        },
        
        height: 800,


      };

      var chart = new google.charts.Line(document.getElementById('linechart_material'));

      chart.draw(data, options);


    }
  </script>
</head>
<body>
<p><a href="http://ice2015.eqrunner.com">ICE Tent 2015 Daily Report</a></p>
2015-08-27
<div id="linechart_material"></div>
<p align="right"><a href="http://eqrunner.com">Created and run by eqrunner inc</a></p> 
</body>
</html>

Many thank you for your explanation :slight_smile:
I will add it to my TODO list.
The trouble is... I tried PHP and got something working, but I still don't understand it.

Using Google makes it easy. Here are some fun charts and graph examples in HTLM5 without Google.

http://www.williammalone.com/articles/html5-canvas-javascript-bar-graph/