请教edtftpnet下载遇到的超时问题
我要实现一个定时从FTP服务器下载文件到本地的功能,用的第三方类库是 edtftpnet,我是用一个timer,设置它的INTERVAL,每隔比如1分钟去从FTP的某个目录取文件下载下来,具体代码如下:
protected override void OnStart(string[] args)
{
MyTimer tmr = new MyTimer();
tmr.Interval = int.Parse(ds.Tables[0].Rows[i]["intervals"].ToString());
tmr.Directory = ds.Tables[0].Rows[i]["Directory"].ToString();
tmr.HistoryPath = ds.Tables[0].Rows[i]["historypath"].ToString();
tmr.Path = ds.Tables[0].Rows[i]["path"].ToString();
tmr.Type = ds.Tables[0].Rows[i]["type"].ToString();
tmr.Elapsed += new ElapsedEventHandler(tmr_Tick);
tmr.AutoReset = true;
tmr.Start();
}
private void tmr_Tick(object sender, ElapsedEventArgs e)
{
MyTimer _timer = (MyTimer)sender;
_timer.Enabled = false;
if (_timer.Type == "download")
DownloadFile(_timer.Directory, _timer.HistoryPath, _timer.Path);
_timer.Enabled = true;
}
public void DownloadFile(string DirectoryName, string HistoryPath, string Path)
{
FTPConnection ftpConn = new FTPConnection();
try
{
ftpConn.UserName = System.Configuration.ConfigurationSettings.AppSettings["UserName"];
ftpConn.Password = System.Configuration.ConfigurationSettings.AppSettings["Password"];
ftpConn.ServerAddress = System.Configuration.ConfigurationSettings.AppSettings["ServerAddress"];
ftpConn.ServerPort = int.Parse(System.Configuration.ConfigurationSettings.AppSettings["ServerPort"]);
ftpConn.TransferType = FTPTransferType.BINARY;
ftpConn.Connect();
ftpConn.WorkingDirectory = DirectoryName;
string directory = ftpConn.WorkingDirectory;
....
ftpConn.DownloadFile(Path, filetemp);
}
catch(Exception ex)
{
}
finally
{
if (ftpConn.IsConnected)
ftpConn.Close();
}
}
最后一直报错:System.IO.IOException: Failed to connect to 115.236.10.243:45663 within timeout 120000 ms
在 EnterpriseDT.Net.StandardSocket.InternalConnect(EndPoint remoteEP, Int32 timeout)
在 EnterpriseDT.Net.StandardSocket.Connect(EndPoint remoteEP, Int32 timeout)
在 EnterpriseDT.Net.Ftp.FTPControlSocket.NewPassiveDataSocket(String ipAddress, Int32 port)
在 EnterpriseDT.Net.Ftp.FTPControlSocket.CreateDataSocketPASVInternal()
在 EnterpriseDT.Net.Ftp.FTPControlSocket.CreateDataSocketPASV()
在 EnterpriseDT.Net.Ftp.FTPControlSocket.CreateDataSocket(FTPConnectMode connectMode)
在 EnterpriseDT.Net.Ftp.FTPClient.Dir(String dirname, Boolean full, LineCallback lineCallback, Object state)
在 EnterpriseDT.Net.Ftp.FTPClient.Dir(String dirname, Boolean full)
在 EnterpriseDT.Net.Ftp.FTPClient.DirDetails(String dirname)
在 EnterpriseDT.Net.Ftp.FTPConnection.GetFileInfos(String directory)
在 FTPService.FTPService.DownloadFile(String DirectoryName, String HistoryPath, String Path) 位置 C:\Code\FTPService\FTPService\FTPService.cs:行号 128
但是文件能下载下来,设置timeout属性也没用的,我已经试过了,请教高手这是什么原因