yer then it must be my code if I just try and convert the code to use it with sdfat this is what I am getting as an error
FTP_Upload.ino:282:27: error: invalid suffix "_READ" on integer constant
FTP_Upload.ino: In function 'byte doFTP()':
FTP_Upload:81: error: no match for 'operator=' in 'fh = file.SdFile::.SdBaseFile::open(((const char*)((char*)(& fileName))), 1u)'
C:\arduino-1.0.3\libraries\SdFat/SdFile.h:32: note: candidates are: SdFile& SdFile::operator=(const SdFile&)
FTP_Upload:87: error: no match for 'operator!' in '!fh'
FTP_Upload.ino:87: note: candidates are: operator!(bool)
FTP_Upload.ino: In function 'void readSD()':
FTP_Upload:284: error: no match for 'operator!' in '!fh'
FTP_Upload.ino:284: note: candidates are: operator!(bool)
I have only really added the
#include <SdFat.h>
#include <SdFatUtil.h>
#define error(s) sd.errorHalt_P(PSTR(s))
SdFat sd;
SdFile fh;
SdFile file;
const uint8_t chipSelect = SS;
and removed the File = fh
/*
FTP passive client for IDE v1.0.1 and w5100/w5200
Posted October 2012 by SurferTim
*/
#include <SdFat.h>
#include <SdFatUtil.h>
#include <Ethernet.h>
#include <SPI.h>
// comment out next line to write to SD from FTP server
#define FTPWRITE
#define error(s) sd.errorHalt_P(PSTR(s))
SdFat sd;
SdFile fh;
SdFile file;
const uint8_t chipSelect = SS;
// this must be unique
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x59, 0x67 };
char serverName[] = "update.fpt.com";
// change to your network settings
IPAddress ip( 192, 168, 3, 177 );
IPAddress gateway( 192, 168, 3, 254 );
IPAddress subnet( 255, 255, 255, 0 );
// change to your server
//IPAddress server(serverName);
EthernetClient client;
EthernetClient dclient;
char outBuf[128];
char outCount;
// change fileName to your file (8.3 format!)
char fileName[13] = "10001602.TXT";
void setup()
{
Serial.begin(9600);
pinMode(10,OUTPUT);
digitalWrite(10,HIGH);
if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();
Ethernet.begin(mac, ip, gateway, gateway, subnet);
digitalWrite(10,HIGH);
delay(2000);
Serial.println("Ready. Press f or r");
}
void loop()
{
byte inChar;
inChar = Serial.read();
if(inChar == 'f')
{
if(doFTP()) Serial.println("FTP OK");
else Serial.println("FTP FAIL");
}
if(inChar == 'r')
{
readSD();
}
}
byte doFTP()
{
#ifdef FTPWRITE
fh = file.open(fileName, O_READ);
#else
SD.remove(fileName);
fh = file.open(fileName,FILE_WRITE);
#endif
if(!fh)
{
Serial.println("SD open fail");
return 0;
}
#ifndef FTPWRITE
if(!fh.seek(0))
{
Serial.println("Rewind fail");
fh.close();
return 0;
}
#endif
Serial.println("SD opened");
if (client.connect(serverName,21)) {
Serial.println("Command connected");
}
else {
fh.close();
Serial.println("Command connection failed");
return 0;
}
if(!eRcv()) return 0;
client.write("USER test\r\n");
if(!eRcv()) return 0;
client.write("PASS pas!\r\n");
if(!eRcv()) return 0;
client.write("SYST\r\n");
if(!eRcv()) return 0;
client.write("PASV\r\n");
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("Bad PASV Answer");
}
}
unsigned int hiPort,loPort;
hiPort = array_pasv[4] << 8;
loPort = array_pasv[5] & 255;
Serial.print("Data port: ");
hiPort = hiPort | loPort;
Serial.println(hiPort);
if (dclient.connect(serverName,hiPort)) {
Serial.println("Data connected");
}
else {
Serial.println("Data connection failed");
client.stop();
fh.close();
return 0;
}
#ifdef FTPWRITE
client.write("STOR ");
client.println(fileName);
#else
client.write("RETR ");
client.println(fileName);
#endif
if(!eRcv())
{
dclient.stop();
return 0;
}
#ifdef FTPWRITE
Serial.println("Writing");
byte clientBuf[64];
int clientCount = 0;
while(fh.available())
{
clientBuf[clientCount] = fh.read();
clientCount++;
if(clientCount > 63)
{
Serial.println("Packet");
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("Data disconnected");
if(!eRcv()) return 0;
client.write("QUIT\r\n");
if(!eRcv()) return 0;
client.stop();
Serial.println("Command disconnected");
fh.close();
Serial.println("SD closed");
return 1;
}
//************************************ errors**************
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.write("QUIT\r\n");
while(!client.available()) delay(1);
while(client.available())
{
thisByte = client.read();
Serial.write(thisByte);
}
client.stop();
Serial.println("Command disconnected");
fh.close();
Serial.println("SD closed");
}
void readSD()
{
fh = file.open(fileName,0_READ);
if(!fh)
{
Serial.println("SD open fail");
return;
}
while(fh.available())
{
Serial.write(fh.read());
}
fh.close();
}