Search code examples
c#ftpconnection

How to check FTP connection?


Is there a simple, fast way to check that a FTP connection (includes host, port, username and password) is valid and working? I'm using C#. Thank you.


Solution

  • try something like this:

    FtpWebRequest requestDir = (FtpWebRequest)FtpWebRequest.Create("ftp://ftp.google.com");
    requestDir.Credentials = new NetworkCredential("username", "password");
    try
    {
         WebResponse response = requestDir.GetResponse();
         //set your flag
    }
    catch
    {
    }