• FTP多任务下载实现类


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Threading;
    using System.Net;
    using System.IO;
    
    namespace RSGIS.FTPClient
    {
        public partial class FormLoad : DevExpress.XtraEditors.XtraForm
        {
            private string host = "ftp://...:21";
            private string user = "anonymous";
            private string pass = "...";
    
            private string strLocalFilePath = @"D:";
            private string[] strLists;
            private List<MultiFtpService> MultiThread = new List<MultiFtpService>();
            public FormLoad(string[] strList)
            {
                InitializeComponent();
                strLists = strList;
            }
    
            public FormLoad()
            {
                InitializeComponent();
                strLists = new string[3];
                strLists[0] = “”
                strLists[1] = “”
                strLists[2] = “”
    
            private void buttonStart_Click(object sender, EventArgs e)
            {
                taskDo();
            }
    
            private void buttonStop_Click(object sender, EventArgs e)
            {
                stop();
            }
    
            private void buttonContinues_Click(object sender, EventArgs e)
            {
                continues();
            }
            //停止
            private void stop()
            {
                for (int i = 0; i < MultiThread.Count; i++)
                {
                    MultiThread[i].Stop();
                }
            }
            //继续
            private void continues()
            {
                for (int i = 0; i < MultiThread.Count; i++)
                {
                    MultiThread[i].continues();
                }
            }
            //下载
            private void taskDo()
            {
                for (int i = 0; i < strLists.Length; i++)
                {
                    string[] files = fileName(strLists[i], strLists[i].Substring(strLists[i].LastIndexOf("/") + 1));
                    MultiFtpService threads = new MultiFtpService(host, user, pass, i, i, files[0], files[1]);
                    MultiThread.Add(threads);
                    threads.WorkMethod += DisplayProgress;
                    threads.FileSpeedMethod += DisplaySpeed;
                    threads.Start();
                }
            }
            //路径操作
            private string[] fileName(string strRemoteFilePath, string strLocalFileName)
            {
                string strLocalFilePaths = strLocalFilePath + @"" + strLocalFileName;
                strLocalFilePaths.Replace("\\", "\");
                strRemoteFilePath.Replace("/", "\");
                string[] files = { strRemoteFilePath, strLocalFilePaths };
                return files;
            }
            /// <summary>
            /// 进度显示
            /// </summary>
            /// <param name="threadindex"></param>
            /// <param name="taskindex"></param>
            /// <param name="progress"></param>
            private void DisplayProgress(int taskindex, int progress)
            {
                this.BeginInvoke(new MethodInvoker(delegate()
                {
                    label1.Text = taskindex.ToString();
                    this.progressBar2.Value = progress;
                    if(progress == 100)
                        this.progressBar2.Value = progressBar2.Maximum;
                }));
            }
            //下载速度显示
            private void DisplaySpeed(int taskindex, string speed)
            {
                this.BeginInvoke(new MethodInvoker(delegate()
                {
                    this.labelSpeed.Text = speed + "/s";
                }));
                
            }
    
        }
    }
    

      

  • 相关阅读:
    Java第十三天,内部类
    Java第十二天,权限修饰符
    Java面向对象基础
    opencv配置(win10+VS2015+opencv3.1)
    malloc函数
    C++用new创建对象和不用new创建对象的区别解析
    字符串匹配KMP算法中Next[]数组和Nextval[]数组求法
    C++将一个数组内容赋给另一个数组
    C++中的const和指针组合
    通过图片对比带给你不一样的KMP算法体验
  • 原文地址:https://www.cnblogs.com/lxc-binary/p/3461550.html
Copyright © 2020-2023  润新知