-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add FTP Client library #1183
Comments
try to use it like this dclient.write((const uint8_t *) &clientBuf[0], 64); for a faster upload you shut increase the 64 to 1460. |
Hello Markus, One question of curiosity, how do found out, what to do? |
I read the error message, then I take a look to the code. size_t write(const uint8_t *buf, size_t size); with what you try to give in.
|
Hello Markus, Unfortunately I looked at line 115 of WiFiClient.h, which was mentioned in the error message: The increased buffer size (1460) works also. Regards, Rudolf |
Hello Markus, |
It would be very useful for others to create a library from this example. |
Hello Ivan, Regards, Rudolf |
I have added an upload / download flag to the program: Regards, Rudolf |
Rudi, must say awesome work. I have tried example with my server it starts all good asks for user Here is serial log: WiFi connected; IP address: 192.168.0.11 Thanks Dans |
PS my server is a just host one, account works fine tested with FTP client. Dans |
Rudi Update. All working, I removed from the client.print lines the F pointer to store string in ram. All works perfect without it on ESP :) Superb work, finally can FTP files to a server brilliant work. Would be nice to wrap this lot up in a library. Dans |
Hello Dans, |
Hi Rudi, Really strange I am using 1.6.5 with latest staging version and your example sketch. First of all would sit there after sending password and wait 15 mins for FTP server disconnection. I added to your ercv() routine a ten second time-out and tried again, timed out after every attempt so I knew it was just waiting for response from ftp server. Just as a try I removed the F pointer from password and username, tried again and it proceeded further. I then removed all of them from the doFtp routine and hey presto works like a treat. Maybe Igrr could shed some light on this. I am very happy, have tested it today solidly and works every time. A big thanks again for all your hard work. Dans |
Hello Dans, |
Hi Rudi, I have had great success with this and am in the process of wrapping it all up in a library with additional functionality added. Can you give me a list of all the credits to include within my library. Version history amendments etc. Big thanks again Dans |
Hello Dans, |
Hey rudi48, I am trying to do something similar but keep running into roadblocks. I am trying to just simply write a "hello" onto a text file on an ftp server. The Arduino with the ESP8266 chip is communicating just fine with the FTP server through the Serial Monitor AT commands, but I am having trouble applying your code. I don't have an SD card reader / writer. Would you be able to help me with developing a code that simply writes "hello" onto a text file on an ftp server? Once I can do that, I can figure out how to transmit the data from multiple sensors onto the ftp server, and access it remotely from another location, which is my main goal. Any assistance would be greatly appreciated. Thank you! -Gene |
Hello Gene, |
.. |
Hi, I need the ESP/Arduino setup to act as a client and upload a text file periodically to the ftp server. |
Hi akashboghani, Did you solve the problem? I assume you have the ESP8266 module wired to an Arduino board? I connect successfully to my FTP server & I am able to manipulate the directories etc I am also able to get my Dataport but I have no idea how to connect to it. The ESP8266wifi.h seems to only allow one client connection at a time........I must be missing something very simple! Thanks |
the code is not working, the SPIFFS open fail ! |
@stabraqmahmood
|
@rudi48 i`m using nodemcu v 1.0 (esp12-e) on arduino IDE v 1.6.12 |
@stabraqmahmood |
Hi rudi48 // Set these to your desired softAP credentials. They are not configurable at runtime. //boolean debug = false; // true = more messages // LED is needed for failure signalling unsigned long startTime = millis(); // provide text for the WiFi status // provide text for the WiFi mode // change to your server WiFiClient client; char outBuf[128]; // change fileName to your file (8.3 format!) void signalError() { // loop endless with LED blinking in case of error //format bytes String formatBytes(size_t bytes) { //----------------------- WiFi handling WiFi.begin ( ssid, password ); if (debug ) WiFi.printDiag(Serial); // ... Give ESP 10 seconds to connect to station. //----------------- FTP fail client.println(F("QUIT")); while (!client.available()) delay(1); while (client.available()) { client.stop(); //-------------- FTP receive while (!client.available()) delay(1); respCode = client.peek(); outCount = 0; while (client.available()) {
} if (respCode >= '4') { //--------------- FTP handling if (upload) { if (!myFile) { if (upload) { if (debug) Serial.println(F("SD opened")); if (client.connect(server, 21)) { // 21 = FTP server if (!eRcv()) return 0; if (!eRcv()) return 0; if (!eRcv()) return 0; if (!eRcv()) return 0; if (!eRcv()) return 0; if (!eRcv()) return 0; char *tStr = strtok(outBuf, "(,"); if (debug) Serial.print(F("Data port: ")); if (dclient.connect(server, hiPort)) { if (upload) { if (!eRcv()) { if (upload) {
} else { dclient.stop(); if (!eRcv()) return 0; client.println(F("QUIT")); if (!eRcv()) return 0; client.stop(); myFile.close(); void readSD() if(!myFile) while(myFile.available()) myFile.close(); Serial.print("Chip ID: 0x"); Serial.println ( "Connect to Router requested" ); if (!SD.begin(4) == 0) { // Check to see if the file exists: /* void loop() { if (Serial.available() > 0) { boolean upload = true; // false = download if (inChar == 'd') { if (inChar == 'u') { if (inChar == 'r') { ` I can't compile the code it give me error
` |
If in doFTP you change: to
(char changed to byte), at least it compiles error-free. |
No, I do not have the expertise to do so. |
Hello rudi or everybody who can help. Wifi is working fine. I added FTP client functionality, it works fine (I can connect to Filezilla Server) but I can't send "data" of my ASCII file. I supposed that I would create 2 FTP clients (as your code with "client" and "dclient") but it don't work. Do you have an idea to help me, pls ? |
@TomElectronic you're in the wrong place, you're talking about the AT firmware, but this is the Arduino firmware. |
Yes, you're right, I'm sorry... But this is the only code that I found who use 2 client with ESP8266. I just wrote a message on espressif forum that I found after that post. Thanks, |
Hello everybody. Is there a way to realize a secure ftp connection with esp8266 and this client? I mean FTPS one. I used WiFiClientSecure to open control socket and plain WiFiClient for data - it works fine. Unfortunately client can not make secure connection on data. And as far as I understand it is not 'lack of memory' problem - I tried to open secure control connections on two independent servers, worked too. Is it possible to make data connection secured too? Thanks. |
I have this code working on my ESP8255. It will connect and transfer a file to my Mac but will not do so to my Raspberry Pi, with ProFTPD server. I can connect/transfer to the RPi using Filezilla. Can someone please help. I wish to FTP from the ESP to the RPi. WiFi connected; IP address: 192.168.2.100 Thanks. |
Dans, Have you converted this into Library? It would help us a lot! |
Reducing 2.7.0 scope, pushing back |
I have worked on that code base a little bit and put together a working library that features
Maybe you want to give this a try and check it out. See https://github.com/dplasa/esp8266FTPServer |
Hi,
This has been a long time ago since I tinkered with this. I have attached
the class module I created for this, allows upload and download to FTP
server wrapped up in a class module.
Hope this helps.
Regards
Dans
On Tue, May 26, 2020 at 5:44 PM Daniel Plasa ***@***.***> wrote:
I have had great success with this and am in the process of wrapping it
all up in a library with additional functionality added.
Dans, Have you converted this into Library? It would help us a lot!
I have worked on that code base a little bit and put together a working
library that features
- LittleFS (including directory support) / SPIFFS support
- active and passive mode FTP
- supports ftp FEAT, SIZE, MSLD, MDTM commands
- works nicely with ftp command or FileZilla
Maybe you want to give this a try and check it out. See
https://github.com/dplasa/esp8266FTPServer
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1183 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC5RNF6ORZA4SATQRSQSZBDRTPWVRANCNFSM4BWJA46A>
.
/*
Wrapper for FTP functionality using ESP8266
Created by Danbicks.
Additonal functions added for getting setting filename / paths
Debug option for additional serial logging.
Credits: Surfer Tim for Ino Arduino sketch Implementation 2015-12-09
Updates by : Rudolf Reuter
Library development and additional functions: Danbicks 24/02/2016
*/
#ifndef DBFTP_h
#define DBFTP_h
#include "Arduino.h"
#include <WiFiClient.h>
#include "FS.h"
class DBFTP
{
public:
void SetFilename(String VarFile);
void SetPathName(String VarPath);
void SetFtpServer(String VarServer);
void SetFtpPort(int VarPort);
void SetFtpUser(String VarUser);
String GetFilename();
String GetPathName();
String GetFtpServer();
int GetFtpPort();
String GetFtpUser();
void SetDebug(bool VarDebug);
byte doFTP(boolean upload);
String formatBytes(size_t bytes);
private:
// private functions and alias
WiFiClient client;
WiFiClient dclient;
byte eRcv();
void efail();
//String formatBytes(size_t bytes);
// Private Variables etc
int _pin;
boolean debug = true; // true = more messages
char outBuf[128]; // was 128
char outCount;
// change fileName to your file (8.3 format!)
String fileName = "WT06.txt";
String path = "/WT06.json";
String FTP_Server = "ftp.dbtec.org";
int FTP_Port = 21;
String FTP_User = "ESP1@dbtec.org";
String FTP_Pwd = "Electr0nics_1234";
File fh; // SPIFFS file handle
};
/*
------------------------------------------------------------------------------------
CLASS FUNCTIONS UTILS
------------------------------------------------------------------------------------
*/
void DBFTP::SetFilename(String VarFile)
{
fileName = VarFile;
}
String DBFTP::GetFilename()
{
return fileName;
}
//--------------------------------------------------------------------
void DBFTP::SetPathName(String VarPath)
{
path = VarPath;
}
String DBFTP::GetPathName()
{
return path;
}
//--------------------------------------------------------------------
void DBFTP::SetFtpServer(String VarServer)
{
FTP_Server = VarServer;
}
String DBFTP::GetFtpServer()
{
return FTP_Server;
}
//--------------------------------------------------------------------
void DBFTP::SetFtpPort(int VarPort)
{
FTP_Port = VarPort;
}
int DBFTP::GetFtpPort()
{
return FTP_Port;
}
//--------------------------------------------------------------------
void DBFTP::SetFtpUser(String VarUser)
{
FTP_User = VarUser;
}
String DBFTP::GetFtpUser()
{
return FTP_User;
}
//--------------------------------------------------------------------
void DBFTP::SetDebug(bool VarDebug)
{
if (VarDebug)
{
debug = true;
}
else
{
debug = false;
}
}
/*
------------------------------------------------------------------------------------
CLASS FUNCTIONS FTP SPECIFIC
------------------------------------------------------------------------------------
*/
byte DBFTP::doFTP(boolean upload)
{
Serial.println("Starting FTP Process..");
if (upload) {
fh = SPIFFS.open(path, "r");
} else {
SPIFFS.remove(path);
fh = SPIFFS.open(path, "w");
delay(10); // added when create new file
}
if (!fh) {
if (debug) Serial.println("SPIFFS file open has failed!");
return 0;
}
if (upload) {
if (!fh.seek((uint32_t)0, SeekSet))
{
Serial.println("Rewind fail");
fh.close();
return 0;
}
}
if (debug) Serial.println("SPIFFS file opened");
if (client.connect(FTP_Server.c_str(), FTP_Port))
{ // 21 = FTP server
if (debug) Serial.println("FTP Server connected");
}
else
{
fh.close();
if (debug) Serial.println("Could not connect to FTP Server Check Settings....");
return 0;
}
if (!eRcv()) return 0;
if (debug) Serial.println("Send USER");
client.print("USER "); client.println(FTP_User);
if (!eRcv()) return 0;
if (debug) Serial.println("Send PASSWORD");
client.print("PASS "); client.println(FTP_Pwd);
if (!eRcv()) return 0;
if (debug) Serial.println("Send SYST");
client.println("SYST");
if (!eRcv()) return 0;
if (debug) Serial.println("Send Type I");
client.println("Type I");
if (!eRcv()) return 0;
if (debug) Serial.println("Send PASV");
client.println("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) {
if (debug) Serial.println("Bad PASV Answer");
}
}
unsigned int hiPort, loPort;
hiPort = array_pasv[4] << 8;
loPort = array_pasv[5] & 255;
if (debug) Serial.print("Data port: ");
hiPort = hiPort | loPort;
if (debug) Serial.println(hiPort);
if (dclient.connect(FTP_Server.c_str(), hiPort)) {
if (debug) Serial.println("Data connected");
}
else {
if (debug) Serial.println("Data connection failed");
client.stop();
fh.close();
return 0;
}
if (upload) {
if (debug) Serial.println("Send STOR filename");
client.print("STOR ");
client.println(fileName);
} else {
if (debug) Serial.println("Send RETR filename");
client.print("RETR ");
client.println(fileName);
}
if (!eRcv()) {
dclient.stop();
return 0;
}
if (upload) {
if (debug) Serial.println("Writing");
#define bufSizeFTP 1460
uint8_t clientBuf[bufSizeFTP];
size_t clientCount = 0;
while (fh.available()) {
clientBuf[clientCount] = fh.read();
clientCount++;
if (clientCount > (bufSizeFTP - 1)) {
dclient.write((const uint8_t *) &clientBuf[0], bufSizeFTP);
clientCount = 0;
delay(1);
}
}
if (clientCount > 0) dclient.write((const uint8_t *) &clientBuf[0], clientCount);
} else {
while (dclient.connected()) {
while (dclient.available()) {
char c = dclient.read();
fh.write(c);
if (debug) Serial.write(c);
}
}
}
dclient.stop();
if (debug) Serial.println("Data disconnected");
if (!eRcv()) return 0;
client.println("QUIT");
if (!eRcv()) return 0;
client.stop();
if (debug) Serial.println("Command disconnected");
fh.close();
if (debug) Serial.println("SPIFFS closed");
return 1;
} // doFTP()
//--------------------------------------------------------------------
byte DBFTP::eRcv()
{
byte respCode;
byte thisByte;
int loopCount = 0;
if (debug) Serial.println("Start eRcv Reset Counter..");
while (!client.available())
{
delay(1);
loopCount++;
// if nothing received for 10 seconds, timeout
if(loopCount > 15000)
{
client.stop();
Serial.println("15 secTimeout");
return 0;
}
}
respCode = client.peek();
outCount = 0;
while (client.available())
{
thisByte = client.read();
if (debug) Serial.write(thisByte); // MODDED HERE IF DEBUG
if (outCount < 127) // was 127
{
outBuf[outCount] = thisByte;
outCount++;
outBuf[outCount] = 0;
}
}
if (respCode >= '4')
{
if (debug) Serial.println("Efail...");
efail();
return 0;
}
if (debug)Serial.println("Return DB Ok..");
return 1;
} // end of eRcv()
//--------------------------------------------------------------------
void DBFTP::efail()
{
byte thisByte = 0;
client.println("QUIT");
while (!client.available()) delay(1);
while (client.available()) {
thisByte = client.read();
if (debug) Serial.write(thisByte); // MODDED DEBUG ADDITION
}
client.stop();
if (debug) Serial.println("Command disconnected");
fh.close();
if (debug) Serial.println("Spiffs file closed");
} // efail
//--------------------------------------------------------------------
String DBFTP::formatBytes(size_t bytes)
{
if (bytes < 1024) {
return String(bytes) + "B";
} else if (bytes < (1024 * 1024)) {
return String(bytes / 1024.0) + "KB";
} else if (bytes < (1024 * 1024 * 1024)) {
return String(bytes / 1024.0 / 1024.0) + "MB";
} else {
return String(bytes / 1024.0 / 1024.0 / 1024.0) + "GB";
}
}
#endif
|
Hi Dans, |
Hi Dan, no Problems. Nice idea to have FTP server running on ESP. I like
it. Probably only good though for small file sharing between a network of
ESP devices. Maybe a good idea to host FTP on a raspberry pi server for
small scale IOT stuff, Another option, would also work well alongside node
RED.
Great work buddy, nice library.
Dans
…On Wed, May 27, 2020 at 1:08 PM Daniel Plasa ***@***.***> wrote:
Hi Dans,
thanks for sharing!
Now that I've read your code, I notice my sloppy reading of this thread...
wile this is all about an ftp *client*, my library provides a ftp *server*
...
:)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1183 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC5RNF2DKR5XYYYYQZL7YZTRTT7C3ANCNFSM4BWJA46A>
.
|
Hey Dans, thanks! After reading your code, that I realized, I could include a client with almost no sweat.... So I took the liberty, to include a ftp client based on your code as well. See https://github.com/dplasa/FTPClientServer ! |
Nice work. Now that there's both a client and server, I suggest the following:
I have some comments about code cleanup and good practices, but we can discuss that in your repo. Finally, I'll add a link to your repo and close this. |
…p8266/Arduino#1183 (comment) which inspired me to the code of the FTPClient
I dplasa, i've tried to use your library, but i got this error every time and i can't transfert a file to FTP server : Transfer failed after 1 ms, code: 4294967295, descr=Local file error. Could you help me to manage it please ? I've attached a screenshot of the error message. |
Hi,
I'm not sure what happens there. Are you using the provided sample as
intended? (That is: serial monitor, use G or P with a valid filename
directly after the G/P, e.g. Ptest.txt or Gtest.txt ) ?
Is the name of the file a valid one on either file system (local or remote)?
Am 02.01.22 um 19:43 schrieb JeffZuckerberg:
…
I have had great success with this and am in the process
of wrapping it all up in a library with additional
functionality added.
Dans, Have you converted this into Library? It would help us a
lot!
I have worked on that code base a little bit and put together a
working library that features
* LittleFS (including directory support) / SPIFFS support
* active and passive mode FTP
* supports ftp FEAT, SIZE, MSLD, MDTM commands
* works nicely with ftp command or FileZilla
Maybe you want to give this a try and check it out. See
https://github.com/dplasa/esp8266FTPServer
<https://github.com/dplasa/esp8266FTPServer>
I dplasa,
i've tried to use your library, but i got this error every time and i
can't transfert a file to FTP server : Transfer failed after 1 ms,
code: 4294967295, descr=Local file error.
Even with the example you provide, i got the same error.
Could you help me to manage it please ? I've attached a screenshot of
the error message.
Best regards,
error dplasa
<https://user-images.githubusercontent.com/41560096/147886077-201d3343-43a2-422f-9316-ca71104019bf.PNG>
—
Reply to this email directly, view it on GitHub
<#1183 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC5FFDI7JDUF7TK2OQZ3FMTUUCMGJANCNFSM4BWJA46A>.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you commented.Message ID:
***@***.***>
|
Hi, I like to adapt http://playground.arduino.cc/Code/FTP to ESP8266.
Most part of the adapted program WiFi_FTP_Client.ino works, but there is a compiler error left,
which I can not resolve.
Most part of the program works, except the file data transfer to the FTP server.
If I declare
const char clientBuf[64] = "aa";
instead of
byte clientBuf[64];
, it works, but that is not what I need.If I use the library
Ethernet.h
instead ofESP8266WiFi.h
it compiles OK, but no data transfer.By the way, if I compile the original program FTP.ino with
Ethernet.h
, I get no compiler error.Please see the error messages (Arduino 1.6.5 and 1.6.6):
Who can help me to solve that puzzle please?
Regards, Rudolf
The program with the error, the error lines are marked:
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: