日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Winform中实现FTP客户端并定时扫描指定路径下文件上传到FTP服务端然后删除文件

發布時間:2025/3/19 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Winform中实现FTP客户端并定时扫描指定路径下文件上传到FTP服务端然后删除文件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

場景

Windows10上怎樣開啟FTP服務:

Windows10上怎樣開啟FTP服務_BADAO_LIUMANG_QIZHI的博客-CSDN博客

上面在Windows上搭建FTP服務器之后,會接收客戶端發來的文件并存儲在指定目錄下,

需要在此臺服務器上再搭建一個FTP客戶端實現定時掃描指定路徑下的文件,并將這些文件

上傳到另一個FTP服務端,上傳成功之后將這些文件刪除,實現文件中轉操作。

找到上面搭建的網站下的FTP身份驗證,雙擊

?

將匿名訪問關閉,開啟身份認證

注:

博客:
BADAO_LIUMANG_QIZHI的博客_霸道流氓氣質_CSDN博客-C#,SpringBoot,架構之路領域博主
關注公眾號
霸道的程序猿
獲取編程相關電子書、教程推送與免費下載。

實現

1、Windows上創建一個新用戶

控制面板-賬戶-家庭和其他用戶-將其他人添加到這臺電腦

2、選擇我沒有這個人的登錄信息

3、選擇添加一個沒有賬戶的用戶

4、然后創建用戶名、密碼、和安全問題等。

5、新建一個Winform項目,設計主頁面布局

6、實現建立連接和列出所有文件的功能

首先新建FtpHelper工具類,該工具類來源與網絡,并對其進行少量修改。

FtpHelper.cs

using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading; using System.Threading.Tasks;namespace UploadFtpServerSchedule {public class FtpHelper{#region 屬性與構造函數/// <summary>/// IP地址/// </summary>public string IpAddr { get; set; }/// <summary>/// 相對路徑/// </summary>public string RelatePath { get; set; }/// <summary>/// 端口號/// </summary>public string Port { get; set; }/// <summary>/// 用戶名/// </summary>public string UserName { get; set; }/// <summary>/// 密碼/// </summary>public string Password { get; set; }public FtpHelper(){}public FtpHelper(string ipAddr, string port, string userName, string password){this.IpAddr = ipAddr;this.Port = port;this.UserName = userName;this.Password = password;}#endregion#region 方法/// <summary>/// 下載文件/// </summary>/// <param name="filePath"></param>/// <param name="isOk"></param>public void DownLoad(string filePath, out bool isOk){string method = WebRequestMethods.Ftp.DownloadFile;var statusCode = FtpStatusCode.DataAlreadyOpen;FtpWebResponse response = callFtp(method);ReadByBytes(filePath, response, statusCode, out isOk);}public void UpLoad(string file, out bool isOk,string filename){isOk = false;FileInfo fi = new FileInfo(file);FileStream fs = fi.OpenRead();long length = fs.Length;string uri = string.Format("ftp://{0}:{1}/{2}", this.IpAddr, this.Port, filename);FtpWebRequest request = (FtpWebRequest)WebRequest.Create(uri);request.Credentials = new NetworkCredential(UserName, Password);request.Method = WebRequestMethods.Ftp.UploadFile;request.UseBinary = true;request.ContentLength = length;request.Timeout = 10 * 1000;try{Stream stream = request.GetRequestStream();int BufferLength = 2048; //2K byte[] b = new byte[BufferLength];int i;while ((i = fs.Read(b, 0, BufferLength)) > 0){stream.Write(b, 0, i);}stream.Close();stream.Dispose();fs.Close();isOk = true;}catch (Exception ex){Console.WriteLine(ex.ToString());}finally{if (request != null){request.Abort();request = null;}}}/// <summary>/// 刪除文件/// </summary>/// <param name="isOk"></param>/// <returns></returns>public string[] DeleteFile(out bool isOk){string method = WebRequestMethods.Ftp.DeleteFile;var statusCode = FtpStatusCode.FileActionOK;FtpWebResponse response = callFtp(method);return ReadByLine(response, statusCode, out isOk);}/// <summary>/// 展示目錄/// </summary>public string[] ListDirectory(out bool isOk){string method = WebRequestMethods.Ftp.ListDirectoryDetails;var statusCode = FtpStatusCode.DataAlreadyOpen;FtpWebResponse response = callFtp(method);return ReadByLine(response, statusCode, out isOk);}/// <summary>/// 設置上級目錄/// </summary>public void SetPrePath(){string relatePath = this.RelatePath;if (string.IsNullOrEmpty(relatePath) || relatePath.LastIndexOf("/") == 0){relatePath = "";}else{relatePath = relatePath.Substring(0, relatePath.LastIndexOf("/"));}this.RelatePath = relatePath;}#endregion#region 私有方法/// <summary>/// 調用Ftp,將命令發往Ftp并返回信息/// </summary>/// <param name="method">要發往Ftp的命令</param>/// <returns></returns>private FtpWebResponse callFtp(string method){string uri = string.Format("ftp://{0}:{1}{2}", this.IpAddr, this.Port, this.RelatePath);FtpWebRequest request; request = (FtpWebRequest)FtpWebRequest.Create(uri);request.UseBinary = true;request.UsePassive = true;request.Credentials = new NetworkCredential(UserName, Password);request.KeepAlive = false;request.Method = method;FtpWebResponse response = (FtpWebResponse)request.GetResponse();return response;}/// <summary>/// 按行讀取/// </summary>/// <param name="response"></param>/// <param name="statusCode"></param>/// <param name="isOk"></param>/// <returns></returns>private string[] ReadByLine(FtpWebResponse response, FtpStatusCode statusCode, out bool isOk){List<string> lstAccpet = new List<string>();int i = 0;while (true){if (response.StatusCode == statusCode){using (StreamReader sr = new StreamReader(response.GetResponseStream())){string line = sr.ReadLine();while (!string.IsNullOrEmpty(line)){lstAccpet.Add(line);line = sr.ReadLine();}}isOk = true;break;}i++;if (i > 10){isOk = false;break;}Thread.Sleep(200);}response.Close();return lstAccpet.ToArray();}private void ReadByBytes(string filePath, FtpWebResponse response, FtpStatusCode statusCode, out bool isOk){isOk = false;int i = 0;while (true){if (response.StatusCode == statusCode){long length = response.ContentLength;int bufferSize = 2048;int readCount;byte[] buffer = new byte[bufferSize];using (FileStream outputStream = new FileStream(filePath, FileMode.Create)){using (Stream ftpStream = response.GetResponseStream()){readCount = ftpStream.Read(buffer, 0, bufferSize);while (readCount > 0){outputStream.Write(buffer, 0, readCount);readCount = ftpStream.Read(buffer, 0, bufferSize);}}}break;}i++;if (i > 10){isOk = false;break;}Thread.Sleep(200);}response.Close();}#endregion}/// <summary>/// Ftp內容類型枚舉/// </summary>public enum FtpContentType{undefined = 0,file = 1,folder = 2} }

然后按鈕與Ftp服務器建立連接的點擊事件

??????? private void button_connnect_ftpserver_Click(object sender, EventArgs e){try{checkNull();if (isRight){ftpHelper = new FtpHelper(ipAddr, port, userName, password);string[] arrAccept = ftpHelper.ListDirectory(out isOk);//調用Ftp目錄顯示功能if (isOk){MessageBox.Show("登錄成功");}}}catch (Exception ex){MessageBox.Show("登錄失敗:ex="+ex.Message);}}

這里調用了非空判斷的校驗方法checkNull

??????? private void checkNull(){isRight = false;//非空校驗ipAddr = this.textBox_addr.Text.Trim();port = this.textBox_port.Text.Trim();userName = this.textBox_name.Text.Trim();password = this.textBox_pass.Text.Trim();if (String.IsNullOrEmpty(ipAddr)){MessageBox.Show("地址不能為空");}else if (String.IsNullOrEmpty(port)){MessageBox.Show("端口不能為空");}else if (String.IsNullOrEmpty(userName)){MessageBox.Show("用戶名不能為空");}else if (String.IsNullOrEmpty(password)){MessageBox.Show("密碼不能為空");}else {isRight = true;}}

然后判斷是否建立連接成功是通過發送列出所有文件的指令的響應來判斷是否建立連接成功。

按鈕列出所有文件的點擊事件

??????? private void button_listDirectory_Click(object sender, EventArgs e){checkNull();if (isRight){ftpHelper = new FtpHelper(ipAddr, port, userName, password);string[] arrAccept = ftpHelper.ListDirectory(out isOk);//調用Ftp目錄顯示功能if (isOk){this.textBox_log.Clear();foreach (string accept in arrAccept){string name = accept.Substring(39);this.textBox_log.AppendText(name);this.textBox_log.AppendText("\r\n");}}else{this.textBox_log.AppendText("鏈接失敗,或者沒有數據");this.textBox_log.AppendText("\r\n");}}}

7、上傳功能實現

選擇上傳的文件按鈕點擊事件

??????? private void button_select_upload_file_Click(object sender, EventArgs e){OpenFileDialog fileDialog = new OpenFileDialog();fileDialog.Multiselect = true;fileDialog.Title = "請選擇文件";if (fileDialog.ShowDialog() == DialogResult.OK){String localFilePath = fileDialog.FileName;//返回文件的完整路徑??????????????this.textBox_upload_path.Text = localFilePath;}}

上傳文件按鈕點擊事件

??????? private void button_upload_Click(object sender, EventArgs e){String uploadPath = this.textBox_upload_path.Text;if (String.IsNullOrEmpty(uploadPath)){MessageBox.Show("上傳文件路徑為空");}else if (!File.Exists(uploadPath)){MessageBox.Show("文件路徑不存在");}else {string filename = Path.GetFileName(uploadPath);ftpHelper.UpLoad(uploadPath, out isOk, filename);if (isOk){??????????MessageBox.Show("上傳文件成功");}else{MessageBox.Show("上傳文件失敗");}}}

上傳文件效果

8、掃描文件并實現單次上傳和刪除文件

選擇掃描文件路徑按鈕點擊事件

??????? private void select_scan_path_Click(object sender, EventArgs e){FolderBrowserDialog path = new FolderBrowserDialog();path.ShowDialog();this.textBox_selected_scan_path.Text = path.SelectedPath;}

掃描文件按鈕點擊事件

??????? private void button_scan_file_Click(object sender, EventArgs e){scanedFileList.Clear();string scanDirectoryPath = this.textBox_selected_scan_path.Text;if (String.IsNullOrEmpty(scanDirectoryPath)){MessageBox.Show("掃描文件路徑不能為空");}else{//指定的文件夾目錄DirectoryInfo dir = new DirectoryInfo(scanDirectoryPath);if (dir.Exists == false){MessageBox.Show("路徑不存在!請重新輸入");}else{this.textBox_scan_file_list.Clear();//檢索表示當前目錄的文件和子目錄FileSystemInfo[] fsinfos = dir.GetFiles();if (fsinfos.Length == 0){this.textBox_scan_file_list.AppendText("未掃描到文件");this.textBox_scan_file_list.AppendText("\r\n");}else {//遍歷檢索的文件和子目錄foreach (FileSystemInfo fsinfo in fsinfos){scanedFileList.Add(fsinfo.FullName);this.textBox_scan_file_list.AppendText(fsinfo.FullName);this.textBox_scan_file_list.AppendText("\r\n");}}}}}

單次上傳掃描的所有文件按鈕點擊事件

??????? private void button_upload_scaned_file_Click(object sender, EventArgs e){if (scanedFileList == null || scanedFileList.Count == 0){MessageBox.Show("沒有掃描到文件");}else {//this.textBox_log.Clear();??????????for (int index = 0;index<scanedFileList.Count;index++) {//執行上傳操作String uploadPath = scanedFileList[index];if (!File.Exists(uploadPath)){this.textBox_log.AppendText(uploadPath + "路徑不存在");this.textBox_log.AppendText("\r\n");}else{string filename = Path.GetFileName(uploadPath);ftpHelper.UpLoad(uploadPath, out isOk, filename);if (isOk){this.textBox_log.AppendText(scanedFileList[index] + "上傳成功");this.textBox_log.AppendText("\r\n");if (File.Exists(uploadPath)){File.Delete(uploadPath);this.textBox_log.AppendText(scanedFileList[index] + "刪除成功");this.textBox_log.AppendText("\r\n");}else{this.textBox_log.AppendText(scanedFileList[index] + "刪除失敗");this.textBox_log.AppendText("\r\n");}}else{this.textBox_log.AppendText(scanedFileList[index] + "上傳失敗");this.textBox_log.AppendText("\r\n");}}}}}

實現效果

9、定時掃描實現

聲明一個全局定時器變量

??????? //定時器System.Windows.Forms.Timer _timer = new System.Windows.Forms.Timer();

定時器啟動按鈕點擊事件

??????? private void button_timer_start_Click(object sender, EventArgs e){decimal interval = this.numericUpDown_interval.Value * 1000;_timer.Interval = (int)interval;_timer.Tick += _timer_Tick;_timer.Start();}

定時器執行的具體事件實現

??????? private void _timer_Tick(object sender, EventArgs e){scanedFileList.Clear();string scanDirectoryPath = this.textBox_selected_scan_path.Text;if (String.IsNullOrEmpty(scanDirectoryPath)){MessageBox.Show("掃描文件路徑不能為空");}else{//指定的文件夾目錄DirectoryInfo dir = new DirectoryInfo(scanDirectoryPath);if (dir.Exists == false){MessageBox.Show("路徑不存在!請重新輸入");}else{this.textBox_scan_file_list.Clear();//檢索表示當前目錄的文件和子目錄FileSystemInfo[] fsinfos = dir.GetFiles();if (fsinfos.Length == 0){this.textBox_scan_file_list.AppendText(DateTime.Now.ToString()+"未掃描到文件");this.textBox_scan_file_list.AppendText("\r\n");}else{//遍歷檢索的文件和子目錄foreach (FileSystemInfo fsinfo in fsinfos){scanedFileList.Add(fsinfo.FullName);this.textBox_scan_file_list.AppendText(fsinfo.FullName);this.textBox_scan_file_list.AppendText("\r\n");}}}}//執行刪除操作if (scanedFileList == null || scanedFileList.Count == 0){this.textBox_log.AppendText(DateTime.Now.ToString()+"沒有掃描到文件");this.textBox_log.AppendText("\r\n");}else{//this.textBox_log.Clear();??????????for (int index = 0; index < scanedFileList.Count; index++){//執行上傳操作String uploadPath = scanedFileList[index];if (!File.Exists(uploadPath)){this.textBox_log.AppendText(DateTime.Now.ToString()+uploadPath + "路徑不存在");this.textBox_log.AppendText("\r\n");}else{string filename = Path.GetFileName(uploadPath);ftpHelper.UpLoad(uploadPath, out isOk, filename);if (isOk){this.textBox_log.AppendText(DateTime.Now.ToString()+scanedFileList[index] + "上傳成功");this.textBox_log.AppendText("\r\n");if (File.Exists(uploadPath)){File.Delete(uploadPath);this.textBox_log.AppendText(DateTime.Now.ToString()+scanedFileList[index] + "刪除成功");this.textBox_log.AppendText("\r\n");}else{this.textBox_log.AppendText(DateTime.Now.ToString()+scanedFileList[index] + "刪除失敗");this.textBox_log.AppendText("\r\n");}}else{this.textBox_log.AppendText(DateTime.Now.ToString()+scanedFileList[index] + "上傳失敗");this.textBox_log.AppendText("\r\n");}}}}}

定時器停止按鈕點擊事件

??????? private void button_timer_stop_Click(object sender, EventArgs e){DialogResult AF = MessageBox.Show("您確定停止計時器嗎?", "確認框", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);if (AF == DialogResult.OK){_timer.Stop();}else{//用戶點擊取消或者關閉對話框后執行的代碼}}

10、完整示例代碼

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;namespace UploadFtpServerSchedule {public partial class Form1 : Form{private FtpHelper ftpHelper;//是否建立連接bool isOk = false;bool isRight = false;string ipAddr = String.Empty;string port = String.Empty;string userName = String.Empty;string password = String.Empty;//存儲掃描的所有文件路徑List<String> scanedFileList = new List<string>();//定時器System.Windows.Forms.Timer _timer = new System.Windows.Forms.Timer();public Form1(){InitializeComponent();}//選擇掃描文件路徑private void select_scan_path_Click(object sender, EventArgs e){FolderBrowserDialog path = new FolderBrowserDialog();path.ShowDialog();this.textBox_selected_scan_path.Text = path.SelectedPath;}//ftp建立連接private void button_connnect_ftpserver_Click(object sender, EventArgs e){try{checkNull();if (isRight){ftpHelper = new FtpHelper(ipAddr, port, userName, password);string[] arrAccept = ftpHelper.ListDirectory(out isOk);//調用Ftp目錄顯示功能if (isOk){MessageBox.Show("登錄成功");}}}catch (Exception ex){MessageBox.Show("登錄失敗:ex="+ex.Message);}}private void checkNull(){isRight = false;//非空校驗ipAddr = this.textBox_addr.Text.Trim();port = this.textBox_port.Text.Trim();userName = this.textBox_name.Text.Trim();password = this.textBox_pass.Text.Trim();if (String.IsNullOrEmpty(ipAddr)){MessageBox.Show("地址不能為空");}else if (String.IsNullOrEmpty(port)){MessageBox.Show("端口不能為空");}else if (String.IsNullOrEmpty(userName)){MessageBox.Show("用戶名不能為空");}else if (String.IsNullOrEmpty(password)){MessageBox.Show("密碼不能為空");}else {isRight = true;}}//列出所有文件private void button_listDirectory_Click(object sender, EventArgs e){checkNull();if (isRight){ftpHelper = new FtpHelper(ipAddr, port, userName, password);string[] arrAccept = ftpHelper.ListDirectory(out isOk);//調用Ftp目錄顯示功能if (isOk){this.textBox_log.Clear();foreach (string accept in arrAccept){string name = accept.Substring(39);this.textBox_log.AppendText(name);this.textBox_log.AppendText("\r\n");}}else{this.textBox_log.AppendText("鏈接失敗,或者沒有數據");this.textBox_log.AppendText("\r\n");}}}//選擇要上傳的文件private void button_select_upload_file_Click(object sender, EventArgs e){OpenFileDialog fileDialog = new OpenFileDialog();fileDialog.Multiselect = true;fileDialog.Title = "請選擇文件";if (fileDialog.ShowDialog() == DialogResult.OK){String localFilePath = fileDialog.FileName;//返回文件的完整路徑 this.textBox_upload_path.Text = localFilePath;}}//上傳文件private void button_upload_Click(object sender, EventArgs e){String uploadPath = this.textBox_upload_path.Text;if (String.IsNullOrEmpty(uploadPath)){MessageBox.Show("上傳文件路徑為空");}else if (!File.Exists(uploadPath)){MessageBox.Show("文件路徑不存在");}else {string filename = Path.GetFileName(uploadPath);ftpHelper.UpLoad(uploadPath, out isOk, filename);if (isOk){ MessageBox.Show("上傳文件成功");}else{MessageBox.Show("上傳文件失敗");}}}//掃描文件private void button_scan_file_Click(object sender, EventArgs e){scanedFileList.Clear();string scanDirectoryPath = this.textBox_selected_scan_path.Text;if (String.IsNullOrEmpty(scanDirectoryPath)){MessageBox.Show("掃描文件路徑不能為空");}else{//指定的文件夾目錄DirectoryInfo dir = new DirectoryInfo(scanDirectoryPath);if (dir.Exists == false){MessageBox.Show("路徑不存在!請重新輸入");}else{this.textBox_scan_file_list.Clear();//檢索表示當前目錄的文件和子目錄FileSystemInfo[] fsinfos = dir.GetFiles();if (fsinfos.Length == 0){this.textBox_scan_file_list.AppendText("未掃描到文件");this.textBox_scan_file_list.AppendText("\r\n");}else {//遍歷檢索的文件和子目錄foreach (FileSystemInfo fsinfo in fsinfos){scanedFileList.Add(fsinfo.FullName);this.textBox_scan_file_list.AppendText(fsinfo.FullName);this.textBox_scan_file_list.AppendText("\r\n");}}}}}//單次上傳掃描的所有文件private void button_upload_scaned_file_Click(object sender, EventArgs e){if (scanedFileList == null || scanedFileList.Count == 0){MessageBox.Show("沒有掃描到文件");}else {//this.textBox_log.Clear(); for (int index = 0;index<scanedFileList.Count;index++) {//執行上傳操作String uploadPath = scanedFileList[index];if (!File.Exists(uploadPath)){this.textBox_log.AppendText(uploadPath + "路徑不存在");this.textBox_log.AppendText("\r\n");}else{string filename = Path.GetFileName(uploadPath);ftpHelper.UpLoad(uploadPath, out isOk, filename);if (isOk){this.textBox_log.AppendText(scanedFileList[index] + "上傳成功");this.textBox_log.AppendText("\r\n");if (File.Exists(uploadPath)){File.Delete(uploadPath);this.textBox_log.AppendText(scanedFileList[index] + "刪除成功");this.textBox_log.AppendText("\r\n");}else{this.textBox_log.AppendText(scanedFileList[index] + "刪除失敗");this.textBox_log.AppendText("\r\n");}}else{this.textBox_log.AppendText(scanedFileList[index] + "上傳失敗");this.textBox_log.AppendText("\r\n");}}}}}private void button_timer_start_Click(object sender, EventArgs e){decimal interval = this.numericUpDown_interval.Value * 1000;_timer.Interval = (int)interval;_timer.Tick += _timer_Tick;_timer.Start();}private void _timer_Tick(object sender, EventArgs e){scanedFileList.Clear();string scanDirectoryPath = this.textBox_selected_scan_path.Text;if (String.IsNullOrEmpty(scanDirectoryPath)){MessageBox.Show("掃描文件路徑不能為空");}else{//指定的文件夾目錄DirectoryInfo dir = new DirectoryInfo(scanDirectoryPath);if (dir.Exists == false){MessageBox.Show("路徑不存在!請重新輸入");}else{this.textBox_scan_file_list.Clear();//檢索表示當前目錄的文件和子目錄FileSystemInfo[] fsinfos = dir.GetFiles();if (fsinfos.Length == 0){this.textBox_scan_file_list.AppendText(DateTime.Now.ToString()+"未掃描到文件");this.textBox_scan_file_list.AppendText("\r\n");}else{//遍歷檢索的文件和子目錄foreach (FileSystemInfo fsinfo in fsinfos){scanedFileList.Add(fsinfo.FullName);this.textBox_scan_file_list.AppendText(fsinfo.FullName);this.textBox_scan_file_list.AppendText("\r\n");}}}}//執行刪除操作if (scanedFileList == null || scanedFileList.Count == 0){this.textBox_log.AppendText(DateTime.Now.ToString()+"沒有掃描到文件");this.textBox_log.AppendText("\r\n");}else{//this.textBox_log.Clear(); for (int index = 0; index < scanedFileList.Count; index++){//執行上傳操作String uploadPath = scanedFileList[index];if (!File.Exists(uploadPath)){this.textBox_log.AppendText(DateTime.Now.ToString()+uploadPath + "路徑不存在");this.textBox_log.AppendText("\r\n");}else{string filename = Path.GetFileName(uploadPath);ftpHelper.UpLoad(uploadPath, out isOk, filename);if (isOk){this.textBox_log.AppendText(DateTime.Now.ToString()+scanedFileList[index] + "上傳成功");this.textBox_log.AppendText("\r\n");if (File.Exists(uploadPath)){File.Delete(uploadPath);this.textBox_log.AppendText(DateTime.Now.ToString()+scanedFileList[index] + "刪除成功");this.textBox_log.AppendText("\r\n");}else{this.textBox_log.AppendText(DateTime.Now.ToString()+scanedFileList[index] + "刪除失敗");this.textBox_log.AppendText("\r\n");}}else{this.textBox_log.AppendText(DateTime.Now.ToString()+scanedFileList[index] + "上傳失敗");this.textBox_log.AppendText("\r\n");}}}}}private void button_timer_stop_Click(object sender, EventArgs e){DialogResult AF = MessageBox.Show("您確定停止計時器嗎?", "確認框", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);if (AF == DialogResult.OK){_timer.Stop();}else{//用戶點擊取消或者關閉對話框后執行的代碼}}} }

總結

以上是生活随笔為你收集整理的Winform中实现FTP客户端并定时扫描指定路径下文件上传到FTP服务端然后删除文件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。