操作超时C#FTP异常 [英] Operation timed out exception C# FTP

查看:839
本文介绍了操作超时C#FTP异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





以下行获取异常操作超时

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;
               }
           }
       }

推荐答案

没有(FTP)服务器使用已使用的URI监听。



检查 directoryPath 是否是有效且现有的URI(ftp:/ /domain.tld)。如果是这样,服务器可能已关闭,或者防火墙静默阻止请求和/或响应。
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.


这篇关于操作超时C#FTP异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆