如何在c#中使用FtpClientCS.dll关闭FTPclient连接?
程序正在使用 FtpClientCS.dll 连接 ftp。 连接失败时,必须重新启动程序。有没有什么函数可以关闭与这个dll的连接?或者我可以做些什么来关闭这里的连接?由于许多程序(主要是 Windows 服务)的大量使用,该 dll 无法替换。
public static FTPclient GetFTPClient(int retry)
{
FTPclient ftpClient = null;
Library.WriteErrorLog("Trying to connect remote server");
try
{
ftpClient = new FTPclient(ConfigurationManager.AppSettings["FTPHost"], ConfigurationManager.AppSettings["FTPUserName"], ConfigurationManager.AppSettings["FTPUserPassword"]);
ftpClient.UsePassive = true;
FTPdirectory ftpDirectory = ftpClient.ListDirectoryDetail(ConfigurationManager.AppSettings["FTPFolderUploadPath"]);
Library.WriteErrorLog("FTP Connected");
}
catch (Exception ex)
{
ftpClient = null;
Library.WriteErrorLog("Unable to connect remote server. Retrying to connect.. " + ex.Message);
Library.WriteErrorLog("Retry time : " + retry);
}
return ftpClient;
}
A program is using FtpClientCS.dll to connect ftp.
When failed to connect, the program must be restarted. Is there any function for closing the connection with this dll? Or is there anything I can do to close the connection here? The dll cannot be replaced due to heavy usage of many programs(basically Windows services).
public static FTPclient GetFTPClient(int retry)
{
FTPclient ftpClient = null;
Library.WriteErrorLog("Trying to connect remote server");
try
{
ftpClient = new FTPclient(ConfigurationManager.AppSettings["FTPHost"], ConfigurationManager.AppSettings["FTPUserName"], ConfigurationManager.AppSettings["FTPUserPassword"]);
ftpClient.UsePassive = true;
FTPdirectory ftpDirectory = ftpClient.ListDirectoryDetail(ConfigurationManager.AppSettings["FTPFolderUploadPath"]);
Library.WriteErrorLog("FTP Connected");
}
catch (Exception ex)
{
ftpClient = null;
Library.WriteErrorLog("Unable to connect remote server. Retrying to connect.. " + ex.Message);
Library.WriteErrorLog("Retry time : " + retry);
}
return ftpClient;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论