我正在尝试通过用c#编写的控制台应用程序访问FTP服务器。我的应用程序在FtpWebRequest.GetResponse()
(尝试/捕获的第一行)中超时。
我可以使用提供给我的凭证和uri +端口通过Filezilla访问FTP服务器。
FtpWebRequest.Timeout
的值。FtpWebRequest.ListDirectory
,FtpWebRequest.ListDirectoryDetails
和FtpWebRequest.DownloadFile
。我尝试使用FtpWebRequest.UsePassive = false
和不使用class Program
{
static void Main(string[] args)
{
//Uri uri = new Uri(@"ftp://1.2.3.4:990/directory/file.csv");
Uri uri = new Uri(@"ftp://1.2.3.4:990/directory");
FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(uri);
ftpRequest.Credentials = new NetworkCredential("username", "password");
//ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
//ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory
ftpRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
//ftpRequest.UsePassive = false;
ftpRequest.Timeout = Convert.ToInt32(0.5d * 60 * 1000);
try
{
FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse();
StreamReader streamReader = new StreamReader(response.GetResponseStream());
List<string> directories = new List<string>();
string line = streamReader.ReadLine();
while (!string.IsNullOrEmpty(line))
{
directories.Add(line);
line = streamReader.ReadLine();
}
}
catch (WebException we)
{
Console.WriteLine("Message:\r\n\t{0}\r\n", we.Message);
Console.WriteLine("Response:\r\n\t{0}\r\n", we.Response);
Console.WriteLine("Response code:\r\n\t{0}\r\n", ((FtpWebResponse)we.Response).StatusCode);
Console.WriteLine("Response StatusDescription:\r\n\t{0}\r\n", ((FtpWebResponse)we.Response).StatusDescription);
Console.WriteLine("Stacktrace:\r\n\t{0}\r\n", we.StackTrace);
}
catch (Exception e) { Console.WriteLine("Exception.ToString:\r\n\t{0}", e.ToString()); }
finally { Console.ReadLine(); }
}
}
。
$Querystatement = $this->db->prepare("SELECT * FROM `production`");
每次运行此代码时,都会收到以下输出。
消息:
操作已超时。
响应:
System.Net.FtpWebResponse
响应码:
未定义
响应状态说明:
Stacktrace:
Syste.NetFtpWebRequest.GetResponse()上的在c:\ Visual Studio 2013 \ Projects \ ConsoleApplication1 \ ConsoleApplication1 \ Program.cs:line27
中的ConsoleApplication1.Program.Main(String [] args)