Hi
I upgraded the firmware on my wifi shield and now I can connect to ftp. The right way to upgrade is located here: not_found. If someone is going to use this link, be careful. You must do EXACTLY the same steps and in EXACTLY the same order.
But though I can connect to my ftp server (connects successfully), when I transfer the file from Arduino, it appears on the server but it's empty. What could cause this?
Here is my sketch.
/*
This sketch connects to a Wifi network.
Then it prints the MAC address of the Wifi shield,
the IP address obtained, and other network details.
Then transfer file from SD card on ftp server (if press f)
Circuit:
* WiFi shield attached
created 13 July 2010
by dlf (Metodo2 srl)
modified 31 May 2012
by Tom Igoe -- WiFi part
October 2012 by SurferTim -- ftp part
October 2013 by Pashkot -- put the parts together (Arduino IDE 1.0.5, Arduino UNO R3)
*/
#include <WiFi.h>
#include <SD.h>
#include <SPI.h>
// comment out next line to write to SD from FTP server
#define FTPWRITE
char ssid[] = "dlink38";Â Â //Â your network SSID (name)
char pass[] = "mypassowrd";Â // your network password
int status = WL_IDLE_STATUS;Â Â // the Wifi radio's status
// change to your server
IPAddress server( 192, 168, 0, 106 );
WiFiClient client;
WiFiClient dclient;
char outBuf[128];
char outCount;
// change fileName to your file (8.3 format!)
char fileName[13] = "test.txt";
void setup() {
 //Initialize serial and wait for port to open:
 Serial.begin(9600);
 //while (!Serial) {
  //; // wait for serial port to connect. Needed for Leonardo only
 //}
Â
 pinMode(10,OUTPUT);
 digitalWrite(10,HIGH);
 if(SD.begin(4) == 0)
 {
  Serial.println(F("SD init fail"));    Â
 }
Â
 // check for the presence of the shield:
 if (WiFi.status() == WL_NO_SHIELD) {
  Serial.println("WiFi shield not present");
  // don't continue:
  while(true);
 }
Â
// attempt to connect to Wifi network:
 while ( status != WL_CONNECTED) {
  Serial.print("Attempting to connect to WPA SSID: ");
  Serial.println(ssid);
  // Connect to WPA/WPA2 network: Â
  status = WiFi.begin(ssid, pass);
  // wait 10 seconds for connection:
  delay(10000);
  // you're connected now, so print out the data:
  Serial.print("You're connected to the network ");
  printCurrentNet();
  printWifiData();
  Serial.print("FTP server:");
  Serial.println(server);
  Serial.println(F("Ready. Press f or r"));
 }
}
void loop() {
 // check the network connection once every 10 seconds:
 //delay(10000);
 //printCurrentNet();
Â
 byte inChar;
 inChar = Serial.read();
 if(inChar == 'f')
 {
  if(doFTP()) Serial.println(F("FTP OK"));
  else Serial.println(F("FTP FAIL"));
 }
 if(inChar == 'r')
 {
  readSD(); Â
 }
}
File fh;
byte doFTP()
{
#ifdef FTPWRITE
 fh = SD.open(fileName,FILE_READ);
#else
 SD.remove(fileName);
 fh = SD.open(fileName,FILE_WRITE);
#endif
 if(!fh)
 {
  Serial.println(F("SD open fail"));
  return 0; Â
 }
#ifndef FTPWRITEÂ
 if(!fh.seek(0))
 {
  Serial.println(F("Rewind fail"));
  fh.close();
  return 0; Â
 }
#endif
 Serial.println(F("SD opened"));
 if (client.connect(server,21)) {
  Serial.println(F("Command connected"));
 }
 else {
  fh.close();
  Serial.println(F("Command connection failed"));
  return 0;
 }
 if(!eRcv()) return 0;
 client.println(F("USER pi"));
 if(!eRcv()) return 0;
 client.println(F("PASS myftppassword"));
 if(!eRcv()) return 0;
 client.println(F("SYST"));
 if(!eRcv()) return 0;
 client.println(F("PASV"));
 if(!eRcv()) return 0;
 char *tStr = strtok(outBuf,"(,");
 int array_pasv[6];
 for ( int i = 0; i < 6; i++) {
  tStr = strtok(NULL,"(,");
  array_pasv[i] = atoi(tStr);
  if(tStr == NULL)
  {
   Serial.println(F("Bad PASV Answer")); Â
  }
 }
 unsigned int hiPort,loPort;
 hiPort = array_pasv[4] << 8;
 loPort = array_pasv[5] & 255;
 Serial.print(F("Data port: "));
 hiPort = hiPort | loPort;
 Serial.println(hiPort);
 if (dclient.connect(server,hiPort)) {
  Serial.println(F("Data connected"));
 }
 else {
  Serial.println(F("Data connection failed"));
  client.stop();
  fh.close();
  return 0;
 }
#ifdef FTPWRITE
 client.print(F("STOR "));
 client.println(fileName);
#else
 client.print(F("RETR "));
 client.println(fileName);
#endif
 if(!eRcv())
 {
  dclient.stop();
  return 0;
 }
#ifdef FTPWRITE
 Serial.println(F("Writing"));
 byte clientBuf[64];
 int clientCount = 0;
 while(fh.available())
 {
  clientBuf[clientCount] = fh.read();
  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);  Â
   Serial.write(c);
  }
 }
#endif
 dclient.stop();
 Serial.println(F("Data disconnected"));
 if(!eRcv()) return 0;
 client.println(F("QUIT"));
 if(!eRcv()) return 0;
 client.stop();
 Serial.println(F("Command disconnected"));
 fh.close();
 Serial.println(F("SD closed"));
 return 1;
}
byte eRcv()
{
 byte respCode;
 byte thisByte;
 while(!client.available()) delay(1);
 respCode = client.peek();
 outCount = 0;
 while(client.available())
 {Â
  thisByte = client.read(); Â
  Serial.write(thisByte);
  if(outCount < 127)
  {
   outBuf[outCount] = thisByte;
   outCount++;  Â
   outBuf[outCount] = 0;
  }
 }
 if(respCode >= '4')
 {
  efail();
  return 0;Â
 }
 return 1;
}
void efail()
{
 byte thisByte = 0;
 client.println(F("QUIT"));
 while(!client.available()) delay(1);
 while(client.available())
 {Â
  thisByte = client.read(); Â
  Serial.write(thisByte);
 }
 client.stop();
 Serial.println(F("Command disconnected"));
 fh.close();
 Serial.println(F("SD closed"));
}
void readSD()
{
 fh = SD.open(fileName,FILE_READ);
 if(!fh)
 {
  Serial.println(F("SD open fail"));
  return; Â
 }
 while(fh.available())
 {
  Serial.write(fh.read());
 }
 fh.close();
}
void printWifiData() {
 // print your WiFi shield's IP address:
 IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
 Serial.println(ip);
 Â
 // print your MAC address:
 byte mac[6];Â
 WiFi.macAddress(mac);
 Serial.print("MAC address: ");
 Serial.print(mac[5],HEX);
 Serial.print(":");
 Serial.print(mac[4],HEX);
 Serial.print(":");
 Serial.print(mac[3],HEX);
 Serial.print(":");
 Serial.print(mac[2],HEX);
 Serial.print(":");
 Serial.print(mac[1],HEX);
 Serial.print(":");
 Serial.println(mac[0],HEX);
}
void printCurrentNet() {
 // print the SSID of the network you're attached to:
 Serial.print("SSID: ");
 Serial.println(WiFi.SSID());
 // print the MAC address of the router you're attached to:
 byte bssid[6];
 WiFi.BSSID(bssid); Â
 Serial.print("BSSID: ");
 Serial.print(bssid[5],HEX);
 Serial.print(":");
 Serial.print(bssid[4],HEX);
 Serial.print(":");
 Serial.print(bssid[3],HEX);
 Serial.print(":");
 Serial.print(bssid[2],HEX);
 Serial.print(":");
 Serial.print(bssid[1],HEX);
 Serial.print(":");
 Serial.println(bssid[0],HEX);
 // print the received signal strength:
 long rssi = WiFi.RSSI();
 Serial.print("signal strength (RSSI):");
 Serial.println(rssi);
 // print the encryption type:
 byte encryption = WiFi.encryptionType();
 Serial.print("Encryption Type:");
 Serial.println(encryption,HEX);
 Serial.println();
}
These are the results of the sketch from serial port:
Attempting to connect to WPA SSID: dlink38
You're connected to the network SSID: dlink38
BSSID: F0:7D:68:9F:E:5A
signal strength (RSSI):-24
Encryption Type:4
IP Address: 192.168.0.107
MAC address: 78:C4:E:2:9:98
FTP server:192.168.0.106
Ready. Press f or r
SD opened
Command connected
220 (vsFTPd 2.3.5)
331 Please specify the password.
230 Login successful.
215 UNIX Type: L8
227 Entering Passive Mode (192,168,0,7,30,106).
Data port: 7786
Data connected
150 Ok to send data.
Writing
Data disconnected
421 Data timeout. Reconnect. Sorry. //after aprox 5 min
And this is the logfile of the server:
pi@raspberrypi ~ $ tail /var/log/vsftpd.log
Thu Oct 31 17:36:08 2013 [pid 2] CONNECT: Client "192.168.0.107"
Thu Oct 31 17:36:08 2013 [pid 1] [pi] OK LOGIN: Client "192.168.0.107"
pi@raspberrypi ~ $
Any ideas,guys?
Btw, MattS-UK thanks for the idea about upgrading the shield, worked out just fine.