0

I have this code to access SFTP:

    private void InitializeSftpConnection()
    {
        FtpHost = _config.GetRequiredValue("FtpHost");
        FtpFolder = _config.GetRequiredValue("FtpFolder");
        FtpUsername = _config.GetRequiredValue("FtpUsername");
        FtpPassword = _config.GetRequiredValue("FtpPassword");

        using (var client = new SftpClient(FtpHost, 22, FtpUsername, FtpPassword))
        {
            client.Connect();
            var files = client.ListDirectory(".").Where(f => f.IsDirectory && f.Name == FtpFolder).Select(f => f.Name);
            if (!files.Any())
            {
                throw new Exception($"Remote FTP folder {FtpFolder} does'nt exist.");
            }
        }
    }

It connects just fine to SFTP, but failing to connect to FTP.

But it is failing on client.Connect(); when I am trying to access regular FTP instead of SFTP. I tried changing port to 21, but it didn't help.

Please advice! Thanks

monstro
  • 6,254
  • 10
  • 65
  • 111

0 Answers0