Click here to Skip to main content
15,923,789 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Getting Exception at below line as"Operation timed out"
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
, please suggest

What I have tried:

public bool FtpDirectoryExists(string directoryPath)
       {
           try
           {
               FtpWebRequest request = (FtpWebRequest)WebRequest.Create(directoryPath);
               request.Method = WebRequestMethods.Ftp.ListDirectory;
               request.Credentials = new NetworkCredential(myftpcreds.UserName, myftpcreds.Password);
               request.KeepAlive = false;
               request.UsePassive = true;
               FtpWebResponse response = (FtpWebResponse)request.GetResponse();

               //request.Timeout = 5000;
              // request.ReadWriteTimeout = 5000;
               return true;
           }
           catch (WebException ex)
           {
               //MessageBox.Show("FtpDirectoryExists");
               return false;
           }
       }
       private void MakeDir(string dirName)
       {
           try
           {
               //create the directory
               FtpWebRequest requestDir = (FtpWebRequest)FtpWebRequest.Create(new Uri(@"ftp://" +  FTPIP + "/" + dirName));
               requestDir.Method = WebRequestMethods.Ftp.MakeDirectory;
               requestDir.Credentials = new NetworkCredential(myftpcreds.UserName,myftpcreds.Password);
               requestDir.UsePassive = true;
               requestDir.UseBinary = true;
               FtpWebResponse response = (FtpWebResponse)requestDir.GetResponse();
               requestDir.KeepAlive = false;
               Stream ftpStream = response.GetResponseStream();
               ftpStream.Close();
               response.Close();
               // return true;
           }
           catch (WebException ex)
           {
               FtpWebResponse response = (FtpWebResponse)ex.Response;
               if (response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
               {
                   response.Close();
                   //   return true;
               }
               else
               {
                   response.Close();
                   //   return false;
               }
           }
       }
Posted
Updated 11-Jul-18 0:20am

1 solution

There is no (FTP) server listening at the used URI.

Check if your directoryPath is a valid and existing URI ("ftp://domain.tld"). If so, the server might be down, or the request and/or response is silently blocked by a firewall.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900