Need example of .NET Core 2.0 using FTP

Advertisement

nishit.2571988@gmail.com
Joined:
Posts:
7
Location:
Ahmedabad

Need example of .NET Core 2.0 using FTP

I have tried with below code with FTP but not work got error like require authentication before user command. I have use WinSCP nuget package latest version in ASP.NET Core 2.0.
Can you please share me one example of ASP.NET Core 2.0 using FTP not SFTP.
var sessionOptions = new SessionOptions
{
    Protocol = Protocol.Ftp,
    HostName = "ftp.hostname.com",
    PortNumber = 21,
    UserName = "ABC@ftp.hostname.com",
    Password = "Test12"
};
try
{
    using (var session = new Session())
    {
        session.Open(sessionOptions);
 
        var transferOptions = new TransferOptions
        {
            TransferMode = TransferMode.Binary
        };
 
        var transferResult = session.GetFiles("/test-destination/*.*",@"C:\test\",
            false, transferOptions);
 
        transferResult.Check();
 
        foreach (TransferEventArgs transfer in transferResult.Transfers)
        {
            Console.WriteLine("Uploaded file: " + transfer.FileName);
        }
    }
 
}
catch (Exception ex)
{
    return false;
}

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,275
Location:
Prague, Czechia

Re: Need example of .NET Core 2.0 using FTP

You have a code for .NET Core 2.0 using FTP. If it does no work, we need full session log file showing the problem (using the latest version of WinSCP).

Also, can you login anyhow? Like using WinSCP GUI? If you can, post its log file too. Or have the GUI generate working code for you:
https://winscp.net/eng/docs/ui_generateurl#code

To generate the session log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Reply with quote

Advertisement

You can post new topics in this forum