Esempio n. 1
0
        /// <summary>
        /// 续传
        /// </summary>
        /// <param name="fileName">本地文件名</param>
        /// <param name="serverFileName">服务文件名</param>
        /// <returns></returns>
        FTPResult ContinueUploadOp(string filename, string serverFileName, string sessionID)
        {
            FTPResult result = new FTPResult();

            if (File.Exists(filename))
            {
                result.Result = 0;
                if (string.IsNullOrWhiteSpace(sessionID))
                {
                    result.SessionID = Guid.NewGuid().ToString();
                }
                else
                {
                    result.SessionID = sessionID;
                }
                result.NewFilename = serverFileName;
                UploadFileList.TryAdd(result.SessionID, new FTPItem()
                {
                    SessionID      = result.SessionID,
                    ServerFilePath = result.NewFilename,
                    LocFilePath    = filename,
                    IsContinue     = true
                });
                Exec();//执行上传 下载
            }
            else
            {
                result.Result = -100;//文件不存在
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// 上传文件,异步实现
        /// 注意如果传输中断,下次再上传时,应该是续传
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="serverFileName">服务文件名</param>
        /// <returns>SessionID,用来多个任务时区分</returns>
        public FTPResult Upload(string filename, string serAddress, string upPath, string serverFilePath)
        {
            FTPResult result = new FTPResult();

            if (File.Exists(filename))
            {
                result.Result    = 0;
                result.SessionID = Guid.NewGuid().ToString();
                if (string.IsNullOrWhiteSpace(serverFilePath))
                {
                    result.NewFilename = string.Concat(serAddress, upPath, result.SessionID, Path.GetExtension(filename));
                }
                else
                {
                    result.NewFilename = serverFilePath;
                }
                UploadFileList.TryAdd(result.SessionID, new FTPItem()
                {
                    SessionID      = result.SessionID,
                    ServerFilePath = result.NewFilename,
                    LocFilePath    = filename,
                    IsContinue     = false
                });
                Exec();//执行上传 下载
            }
            else
            {
                result.Result = -100;//文件不存在
            }
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// 下载文件,异步实现 续传
        /// </summary>
        /// <param name="saveFilename"></param>
        /// <param name="saveFilename"></param>
        /// <returns>SessionID,用来多个任务时区分</returns>
        public FTPResult ContinueDownload(string saveFilename, string remotefilename)
        {
            FTPResult result = new FTPResult();

            result.SessionID   = Guid.NewGuid().ToString();
            result.NewFilename = remotefilename;
            UploadFileList.TryAdd(result.SessionID, new FTPItem()
            {
                SessionID      = result.SessionID,
                ServerFilePath = result.NewFilename,
                LocFilePath    = saveFilename,
                IsContinue     = true,
                IsUpload       = false
            });
            result.Result = 0;
            Exec();//执行上传 下载

            return(result);
        }