【源码】C# 做的FTPClient类库
QFTP.rar
(38.02 KB)
Sample:
程序代码:
QFTP.QFTP Ftp = new QFTP.QFTP(); private void Form1_Load(object sender, EventArgs e) { Ftp.OnFileProgressChanged += new QFTP.QFTP.FileProgressChangedEventHandler(Ftp_OnFileProgressChanged); Ftp.OnError += new QFTP.QFTP.ErrorEventHandler(Ftp_OnError); Ftp.OnGetFileList += new QFTP.QFTP.FileListHandler(Ftp_OnGetFileList); } private void button1_Click(object sender, EventArgs e) { Ftp.DownFtpFile("ftp://192.168.3.4/work18/dotnetfx35.exe", @"D:\TEMP\新建文件夹", "ocr", "ocr"); } private void button2_Click(object sender, EventArgs e) { Ftp.GetFTPFileList("ftp://192.168.3.4/work18", "ocr", "ocr"); } void Ftp_OnGetFileList(object sender, FtpFileListEvent e) { FtpFileList fList = e.FileList; fList.SortByName(); listView1.BeginInvoke(new Action<FtpFileList>((s) => { listView1.Items.Clear(); s.All((s1) => { ListViewItem lvi = listView1.Items.Add(s1.Name); lvi.SubItems.Add(s1.Size.ToString()); lvi.SubItems.Add(s1.Type); lvi.SubItems.Add(s1.ModifiedDate.ToString()); lvi.SubItems.Add(s1.Attributes); //listView1.Items.Add(lvi); return true; }); }), fList); } void Ftp_OnError(object sender, Exception e) { this.Invoke(new Action<string>((s) => { MessageBox.Show(s); }), e.Message); } void Ftp_OnFileProgressChanged(object sender, FtpProgressEvent e) { progressBar1.Invoke(new Action<string, string, long,long>((s, f, v, m) => { label1.Text = string.Format("[{0}] {1} Size: {2}/{3}", s, (f), v, m); progressBar1.Maximum = (int)m; progressBar1.Value = (int)v; }), e.FtpMethod, e.FileName, e.Value, e.Max); }
[ 本帖最后由 qubo1982 于 2011-11-11 17:28 编辑 ]