FTPino - A FTP Client and Server for the Particle

hi @Suprazz, I’m sorry to hear that.

Please post your test file and I’m going to try to reproduce it. I will post a pcap of the result and fix the bugs, if any.

Mihai

Here is the info:

I tried with 2 files, one of 374 bytes and the other 8,5k. Both are not sent completely.

FTPRush output log:

[2] 220 Welcome to FTPino FTP Server.
[2] USER sam
[2] 331 Password required for user sam.
[2] PASS (hidden)
[2] 230 User successfuly logged in.
[2] SYST
[2] 215 UNIX emulated by FTPino.
[2] TYPE A
[2] 200 Type set to BINARY.
[2] REST 1
[2] 350 Restarting at 1. !!! Not implemented
[2] REST 0
[2] 350 Restarting at 0. !!! Not implemented
[2] FEAT
[2] 211 Extensions supported SIZE MDTM XCRC.
[2] PWD
[2] 257 "/" is current directory.
[2] PASV
[2] 227 Entering Passive Mode (192,168,2,155,4,0)
[2] Ouverture de la connexion IP: 192.168.2.155 PORT: 1024
[2] LIST
[2] 150 Opening ASCII mode data connection for transfer.
[2] 226 Transfer complete.
[2] Liste Complete: 520 bytes en 0,00s (0,52KB/s)
[2] PASV
[2] 227 Entering Passive Mode (192,168,2,155,4,0)
[2] Ouverture de la connexion IP: 192.168.2.155 PORT: 1024
[2] REST 0
[2] 350 Restarting at 0. !!! Not implemented
[2] STOR Test.txt
[2] 150 Opening BINARY mode data connection for file transfer.
[2] 226 Transfer complete. 128 bytes written.
[2] MDTM 20160920221659 Test.txt
[2] 502 Command not implemented: MDTM 20160920221659 Test.txt.
[i] Test.txt 374bytes/0,25(s)/0,00Kbps
[i]  1 fichier(s) transfere(s) - Total: 374 byte(s) en 0,25 (0,00 KBps)
[2] PASV
[2] 227 Entering Passive Mode (192,168,2,155,4,0)
[2] Ouverture de la connexion IP: 192.168.2.155 PORT: 1024
[2] LIST
[2] 150 Opening ASCII mode data connection for transfer.
[2] 226 Transfer complete.
[2] Liste Complete: 577 bytes en 0,02s (36,06KB/s)
[2] TYPE I
[2] 200 Type set to BINARY.
[2] PASV
[2] 227 Entering Passive Mode (192,168,2,155,4,0)
[2] Ouverture de la connexion IP: 192.168.2.155 PORT: 1024
[2] REST 0
[2] 350 Restarting at 0. !!! Not implemented
[2] STOR oil-rtestsam.bmp
[2] 150 Opening BINARY mode data connection for file transfer.
[2] 226 Transfer complete. 4736 bytes written.
[2] MDTM 20160714194300 oil-rtestsam.bmp
[2] 502 Command not implemented: MDTM 20160714194300 oil-rtestsam.bmp.
[i] oil-rtestsam.bmp 8,5 kbytes/0,22(s)/37,41Kbps
[i]  1 fichier(s) transfere(s) - Total: 8,5 k byte(s) en 0,22 (37,41 KBps)
[2] TYPE A
[2] 200 Type set to BINARY.
[2] PASV
[2] 227 Entering Passive Mode (192,168,2,155,4,0)
[2] Ouverture de la connexion IP: 192.168.2.155 PORT: 1024
[2] LIST
[2] 150 Opening ASCII mode data connection for transfer.
[2] 226 Transfer complete.
[2] Liste Complete: 577 bytes en 0,00s (0,58KB/s)
[2] (Connexion coupee par l'utilisateur)
[2] ftp://sam:***@192.168.2.155 Deconnecte

Wireshark file and the 2 files I’m using for testing:
https://dl.dropboxusercontent.com/u/25475710/ftp%20issue.zip

I’m running on 0.5.2 and I didn’t changed your code. I’m compiling on windows with the particle compile photon command.

I am not sure I can access the files (maybe a corporate firewall issue?). I’ll try from home. Can you please make sure you enabled external/public access ? Thanks.

I will try to write all of my findings in one post so as to avoid fragmentation of the discussion.

  • I have successfully downloaded the files
  • I have successfully uploaded the files to FTPino. The sizes from both files (oil-rtestsam.bmp and test.txt) are reported the same as the ones on the PC that sent them to FTPino.
  • I have successfully redownloaded the files, the sizes match. I did a binary compare of the contents, identical, no bytes missing. I have tried to open the *.bmp, it opened and displayed correctly.
  • a log of the communication can be found at the appendix of this comment. If you so require, I can also produce a pcap

I am in the process of investigating the code on github and see if there are any differences with the one in the build.parcticle.io cloud (not the library in the cloud, but the code I copy-pasted from github into files I created manually).

I am using:

EDIT 30 Sep 2016 19:49 CET :
I have found no significant difference with the code over on github, other than the server was not enabled by default on my side, benign.

I am posting the main file which includes the init() and setup(), maybe you can check it out? It's in Appendix 2.
My personal feeling is that you are not using the required SDFat library from the particle cloud as described, but are somehow linking it externally. As I understand you are building it directly on your machine? Try to compile it in the cloud, what does that produce?

EDIT 30 Sep 2016 20:16 CET:
I am using Photon firmware v0.5.0.

Mihai

Appendix:

[1] Connecting to 192.168.0.151:21
[1] 220 Welcome to FTPino FTP Server.
[1] USER Mihai
[1] 331 Password required for user Mihai.
[1] PASS (hidden)
[1] 230 User successfuly logged in.
[1] SYST
[1] 215 UNIX emulated by FTPino.
[1] TYPE A
[1] 200 Type set to BINARY.
[1] REST 1
[1] 350 Restarting at 1. !!! Not implemented
[1] REST 0
[1] 350 Restarting at 0. !!! Not implemented
[1] FEAT
[1] 211 Extensions supported SIZE MDTM XCRC.
[1] PWD
[1] 257 "/" is current directory.
[1] PASV
[1] 227 Entering Passive Mode (192,168,0,151,4,0)
[1] Opening data connection IP: 192.168.0.151 PORT: 1024
[1] LIST
[1] 150 Opening ASCII mode data connection for transfer.
[1] 226 Transfer complete.
[1] List Complete: 289 bytes in 0.02 seconds (18.06KB/s)
[1] DELE test.txt
[1] 250 File test.txt was deleted.
[1] PASV
[1] 227 Entering Passive Mode (192,168,0,151,4,0)
[1] Opening data connection IP: 192.168.0.151 PORT: 1024
[1] LIST
[1] 150 Opening ASCII mode data connection for transfer.
[1] 226 Transfer complete.
[1] List Complete: 232 bytes in 0.02 seconds (14.50KB/s)
[1] TYPE I
[1] 200 Type set to BINARY.
[1] Listening at IP: 192.168.0.152 PORT: 4342 for data connecting
[1] PORT 192,168,0,152,16,246
[1] 200 Port command successful.
[1] REST 0
[1] 350 Restarting at 0. !!! Not implemented
[1] STOR test.txt
[1] 150 Opening BINARY mode data connection for file transfer.
[1] 226 Transfer complete. 374 bytes written.
[1] MDTM 20160921041659 test.txt
[1] 502 Command not implemented: MDTM 20160921041659 test.txt.
[i] test.txt 1.1 kbytes/0.23(s)/0.00Kbps
[1] Listening at IP: 192.168.0.152 PORT: 4343 for data connecting
[1] PORT 192,168,0,152,16,247
[1] 200 Port command successful.
[1] REST 0
[1] 350 Restarting at 0. !!! Not implemented
[1] STOR oil-rtestsam.bmp
[1] 150 Opening BINARY mode data connection for file transfer.
[1] 226 Transfer complete. 8694 bytes written.
[1] MDTM 20160715014300 oil-rtestsam.bmp
[1] 502 Command not implemented: MDTM 20160715014300 oil-rtestsam.bmp.
[i] oil-rtestsam.bmp 8.5 kbytes/0.30(s)/27.58Kbps
[i] transferred 2 file(s) - Total: 9.6 k byte(s) in 0.53 (15.43 KBps)
[1] TYPE A
[1] 200 Type set to BINARY.
[1] PASV
[1] 227 Entering Passive Mode (192,168,0,151,4,0)
[1] Opening data connection IP: 192.168.0.151 PORT: 1024
[1] LIST
[1] 150 Opening ASCII mode data connection for transfer.
[1] 226 Transfer complete.
[1] List Complete: 354 bytes in 0.02 seconds (23.60KB/s)
[1] CWD .
[1] 550 Can't change directory to ..
[1] CWD .
[1] 550 Can't change directory to ..
[1] CWD .
[1] 550 Can't change directory to ..
[1] TYPE I
[1] 200 Type set to BINARY.
[1] Listening at IP: 192.168.0.152 PORT: 4347 for data connecting
[1] PORT 192,168,0,152,16,251
[1] 200 Port command successful.
[1] RETR oil-rtestsam.bmp
[1] 150 Opening ASCII mode data connection for transfer.
[1] 226 Transfer complete. 8694 read.
[i] oil-rtestsam.bmp 8.5 kbytes/0.03(s)/271.69Kbps
[1] Listening at IP: 192.168.0.152 PORT: 4348 for data connecting
[1] PORT 192,168,0,152,16,252
[1] 200 Port command successful.
[1] RETR test.txt
[1] 150 Opening ASCII mode data connection for transfer.
[1] 226 Transfer complete. 374 read.
[i] test.txt 374bytes/0.03(s)/12.06Kbps
[i] transferred 2 file(s) - Total: 8.9 k byte(s) in 0.06 (143.94 KBps)
[1] TYPE A
[1] 200 Type set to BINARY.
[1] PASV
[1] 227 Entering Passive Mode (192,168,0,151,4,0)
[1] Opening data connection IP: 192.168.0.151 PORT: 1024
[1] LIST
[1] 150 Opening ASCII mode data connection for transfer.
[1] 226 Transfer complete.
[1] List Complete: 354 bytes in 0.03 seconds (11.42KB/s)
[1] CWD .
[1] (User Disconnect Connection)
[1] ftp://Mihai:***@192.168.0.110 Disconnected

Appendix 2:

#include "Config.h"
// This #include statement was automatically added by the Particle IDE.
#include "SdFat/SdFat.h"

#include "Buzz.h"

// This #include statement was automatically added by the Particle IDE.
#include "FileHandler.h"

// This #include statement was automatically added by the Particle IDE.
#include "FTPServer.h"

#include "FTPClient.h"

#define TIMEZONE (+2)

String user = "Mihai";
String pass = "MfTPpas$";

#ifdef SERVER_ACTIVE
FTPServer *ftpServer = NULL;
#endif

void setup()
{
#ifdef SERVER_ACTIVE
Time.zone(TIMEZONE);
ftpServer = new FTPServer(user, pass, 21, 63);

Particle.publish("FTPinoIP", String(WiFi.localIP()));
pinMode(D7, OUTPUT);
digitalWrite(D7,LOW);
#endif
#ifdef CLIENT_ACTIVE
String ftpAddress   = "192.168.0.151";
String user         = "Mihai";
String pass         = "MfTPpas$";
String fileName = "test.txt";
String stringToWrite= "Lorem Ipsum is simply dummy text of the printing and typesetting industry. "
"Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a "
"galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, "
"but also the leap into electronic typesetting, remaining essentially unchanged. "
"It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently "
"with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
FTPClient ftp (ftpAddress, user, pass);
String result = ftp.send(stringToWrite, fileName);
delay(1000); Particle.publish("Client", result);
#endif

}

void loop()
{
#ifdef SERVER_ACTIVE
auto status = ftpServer->run();
if(status.length()>0) Particle.publish("FTPServer"), delay(1000);
#endif
}

Thanks for the quick answer.

How do do you import your files on build.particle.io??? You copy paste everything manually?

I’m building locally with the cli: particle compile photon C:\myapp

Ok so here is what I did. I copied manually everything in build.particle.io

I was able to compile and flash my device with your code without any modification.

In passive mode:
I’m able to list the content of the SD Card but I have the exact same issue regarding to file upload.
I can download file without problems.

In active mode:
I’m not able to list the content of the sd card but if I try to transfer a file, IT WORKS!!!

So I dont understand why but at least I’m able to copy files knowing that even if I’m not able to list the files in active mode, I’m still able to transfer files correctly.

Tried with 0.5.0, 0.5.3 and 0.6.0rc2

1 Like

really, really strange. I am only using it in passive mode without any modifications. Are you sure you’re using the sdfat 0.0.3 from the particle cloud?

I double checked the connection type in ftprush, it’s passive and I implemented the sources for passive mode, I don’t known what would happen in active mode.

If you’re using sdfat 0.0.3 from the cloud, and tried passive mode with the sources, maybe it’s a hw issue?

I can’t think of anything else right now…

EDIT: I’m using FtpRush v2.1.8 (2.1.8, UNICODE, 2011-11-03).

The problem is not related to storing the data, the problem is related to getting the data over tcp.

I’ll leave that like this for the moment but it really like a low level issue regarding the tcp client. And it’s not the only issue I have right now with tcp client.

BTW Many thanks for you time regarding this!

ok; glad I could be of service. Please keep us posted on this thread if you find anything worth correcting in the sources. Since I cannot find any bugs or cannot reproduce them on my side, I cannot update anything.

1 Like