sparkeh9/CoreFTP

Some working examples please

Closed this issue · 1 comments

I am very new to this been using System.Net.FtpWebrequest up until now but don't know where to start with this library. To get a directory listing was pretty simple using this

` Dim pFtpRequest As System.Net.FtpWebRequest
Dim pftpWebResponse As System.Net.FtpWebResponse
Dim srReader As IO.StreamReader
Dim strResult As String

    pFtpRequest = CType(FtpWebRequest.Create("ftp://ftp.bom.gov.au/anon/gen/fwo/"), FtpWebRequest)

    pFtpRequest.Proxy = New System.Net.WebProxy() 'set empty proxy to avoid http
    pFtpRequest.Method = WebRequestMethods.Ftp.ListDirectory
    pFtpRequest.KeepAlive = False
    pftpWebResponse = CType(pFtpRequest.GetResponse, FtpWebResponse)

    srReader = New StreamReader(pftpWebResponse.GetResponseStream)
    strResult = srReader.ReadToEnd

    srReader.Close()
    srReader.Dispose()
    pFtpRequest.Abort()
    pftpWebResponse.Close()


    Console.Write(strResult)`

Could someone show me how to do the equivalent in CoreFTP, its a public ftp site stick "ftp://ftp.bom.gov.au/anon/gen/fwo/" in a browser or windows file explorer and it just works.

I tired several variants of the code below with and without login and password but it just drops out without even hitting the exception handler. Any help would be greatly appreciated.

`CoreFtp.FtpClient ftpClient;

        CoreFtp.FtpClientConfiguration ftpConfig;

        ftpConfig = new CoreFtp.FtpClientConfiguration();
        ftpConfig.BaseDirectory = "/anon/gen/fwo/";
        ftpConfig.Host = "ftp.bom.gov.au";
        ftpConfig.Username = "anonymous";
        ftpConfig.Password = "guest";
        ftpConfig.Mode = CoreFtp.Enum.FtpTransferMode.Ascii;
    
        ftpClient = new CoreFtp.FtpClient(ftpConfig);
        
        try
        {
           await  ftpClient.LoginAsync();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }`

In the readme it says "The integration test suite provides various example of basic FTP usage."

You can find them here:

https://github.com/sparkeh9/CoreFTP/tree/master/tests/CoreFtp.Tests.Integration/FtpClientTests

I have also added a custom example for you, I've run this and connected successfully to the "Bureau of Meteorology FTP service". The key is to make sure you are in an asynchronous method context, and be able to await the calls.

https://github.com/sparkeh9/CoreFTP/blob/master/tests/CoreFtp.Tests.Integration/FtpClientTests/CustomExamples/When_connecting_to_bom_gov_au.cs