FTP Library

Is the “GHIElectronics.TinyCLR.Networking.Ftp” library targeted for the 2.1 Release, if not is there any update on its release schedule?
Thanks.

The entire source code is there but is has known issues and set at low priority for now. It may just work for you if you want to give it a try.

Thank you @Gus_Issa, will definitely give it a try.
Does anyone have example code showing how to setup an FTP server using this library?
I am looking to upload and download files to the SD Card.
Thanks.

Have explored the FTP server library with minimal success. :slightly_frowning_face:

I have the FtpFilesystemListener running with anonymous user authentication, and FileZilla Client can see the server. The LIST command is being received but no files are showing and client reports a failure.

var ftp = new FtpFilesystemListener(@"/", SDCardInterface.driveName, true);
FtpFilesystemListener.AuthenticationEvent += FtpFilesystemListener_AuthenticationEvent;
ftp.Start();

FileZilla FTP Client log:

Command:	LIST
Response:	150 Opening UTF8 mode data connection for *** 
Response:	503 Bad sequence of commands. 
Error:	Failed to retrieve directory listing

I don’t believe I am setting the VirtualRoot and FileSystemRoot correctly.

The SD Card is mounted as I can produce a correct directory listing in test code prior to setting up the server.

Any suggestions are welcome. Thanks.

may be you are right

FtpFilesystemListener.cs

please take a look at case WebRequestMethods.Ftp.ListDirectory: and also MapToFilesystem and WriteDirInfo methods

could you download source code from ghi github and debug this methods ?

The issue appears to be in how the ftp code uses what you are passing for the filesystemRoot value.

This will work for accessing the root of the SD card:

        var sd = StorageController.FromName(SC20260.StorageController.SdCard);
        var drive = FileSystem.Mount(sd.Hdc);

        var ftp = new FtpFilesystemListener(@"/", drive.Name + "\\", true);
        FtpFilesystemListener.AuthenticationEvent += FtpFilesystemListener_AuthenticationEvent;
        ftp.Start();

and change it to this if you just want to share starting with a directory called ‘ftp’ located at the root of the SD card.

        var ftp = new FtpFilesystemListener(@"/ftp/", drive.Name + "\\ftp", true);

I ran into the same failure you were reporting when the drive name was just “A:” and not “A:\” or “A:\ftp”. Simple drive names that end in a colon seem to break the directory probing code.

I tested this with WinSCP and FileZilla, upload and download, using both the root dir and ‘ftp’ path shown above.

@mcalsyn thank you, really appreciate the assistance. Works as required with your changes.

I note the the FtpFilesystemListener constructor is supposed to add the \\ if not present. See below.

public FtpFilesystemListener(String virtualRoot, String filesystemRoot, bool uploadsAllowed)
        {
            if (filesystemRoot[filesystemRoot.Length - 1] != Path.DirectorySeparatorChar)
            {
                filesystemRoot += Path.DirectorySeparatorChar;
            }

and in System.IO

public static readonly char DirectorySeparatorChar = '\\';

Thank you.

Yes, that is true, but drive.Name already ends in a back-slash, so that code doesn’t run (with or without my change). What we are doing is adding a second backslash so that later, when one gets stripped off (FtpFileSystemListener.cs:87), there’s still one present.

The code works fine in the case where there is a non-empty path, but for root-level dirs, it ends up creating a path that fails in Directory.Exists calls, notably in WriteDirectoryInfo.

I haven’t dug deep enough, but near as I can tell, the code needs to do a bit more to detect and handle root-level directories. Adding the extra trailing back-slash is just a hack to make it work without changing the Library code.

I think the fix may just be to detect the root-dir syntax at FtpFilesystemListener.cs:87 and not remove the trailing slash. That fix will break the hack I provided above, but will restore balance to the universe by removing the need for that hack :wink:

Filed as FtpFilesystemListener fails for root dirs · Issue #1055 · ghi-electronics/TinyCLR-Libraries · GitHub