日期:2014-05-18 浏览次数:21090 次
public class FtpFile { string ftpServerIP; public string FtpServerIP { get { return ftpServerIP; } set { ftpServerIP = value; } } string ftpUserID; public string FtpUserID { get { return ftpUserID; } set { ftpUserID = value; } } string ftpPassword; public string FtpPassword { get { return ftpPassword; } set { ftpPassword = value; } } FtpWebRequest reqFTP; public static string FtpServer = System.Configuration.ConfigurationSettings.AppSettings["FtpServer"]; public static string FtpUser = System.Configuration.ConfigurationSettings.AppSettings["FtpUser"]; public static string FtpPwd = System.Configuration.ConfigurationSettings.AppSettings["FtpPwd"]; private void Connect(String path)//连接ftp { // 根据uri创建FtpWebRequest对象 reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(path)); // 指定数据传输类型 reqFTP.UseBinary = true; // ftp用户名和密码 reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword); } public FtpFile(string ftpServerIP, string ftpUserID, string ftpPassword) { this.ftpServerIP = ftpServerIP; this.ftpUserID = ftpUserID; this.ftpPassword = ftpPassword; } public FtpFile() { this.ftpServerIP = FtpServer; this.ftpUserID = FtpUser; this.ftpPassword = FtpPwd; } }
------解决方案--------------------
你可以启个线程在那里,线程启动后连上FTP,然后循环检查上传或下载的任务,如果有任务就一个一个的处理,在程序退出时再关闭连接。