BeginGetRequestStream() public method

Used to query for the Request stream of an FTP Request [async version]

public BeginGetRequestStream ( AsyncCallback callback, object state ) : IAsyncResult
callback AsyncCallback
state object
return IAsyncResult
コード例 #1
0
ファイル: FTPClient.cs プロジェクト: viticm/pap2
 private void UploadNextFile(IAsyncResult ar)
 {
     //清空
     _currLength = 0;
     _abort = false;
     if (_uploadResponse != null) _uploadResponse.Close();
     if (_fileStream != null) _fileStream.Close();
     if (_requestStream != null) _requestStream.Close();
     _uploadResponse = (FtpWebResponse)_uploadRequest.EndGetResponse(ar);
     //_result = "文件上传成功";
     try
     {
         if (_uploadFiles.Count != 0)
         {
             FileInfo file = _uploadFiles[0] as FileInfo;
             ServerFileInfo serverFile = SearchFile(file.Name.Replace('#', '_'));
             if (serverFile != null) _currLength = serverFile.Size;
             else _currLength = 0;
             string uploadUrl = @"ftp://" + this.Address + ":" + this.Port + "/" + file.Name.Replace('#', '_');
             _uploadRequest = (FtpWebRequest)WebRequest.Create(uploadUrl);
             if ((bool)_uploadFilesStateTable[file])
             {//覆盖
                 _uploadRequest.Method = WebRequestMethods.Ftp.UploadFile;
                 _currLength = 0;
             }
             else _uploadRequest.Method = _currLength == 0 ? WebRequestMethods.Ftp.UploadFile : WebRequestMethods.Ftp.AppendFile; 
             _uploadRequest.Credentials = new NetworkCredential(this.UserName, this.Password);
             _uploadRequest.Proxy = null;
             _uploadRequest.KeepAlive = false;
             _uploadRequest.BeginGetRequestStream(new AsyncCallback(TransFile), file);
         }
     }
     catch (Exception e)
     {
         _result = e.Message;
     }
 }
コード例 #2
0
ファイル: FTPClient.cs プロジェクト: viticm/pap2
 public bool UploadFile(IList files)
 {
     try
     {
         //区分第一次
         if (files != null) _uploadFiles = files;
         _abort = false;
         if (_uploadFiles.Count != 0)
         {
             FileInfo file = _uploadFiles[0] as FileInfo;                    
             //把'#'替换为'_'
             ServerFileInfo serverFile = SearchFile(file.Name.Replace('#','_'));
             if (serverFile != null) _currLength = serverFile.Size;
             else _currLength = 0;
             string uploadUrl = FTP_URL_PREFIX + file.Name.Replace('#', '_');
             _uploadRequest = (FtpWebRequest)WebRequest.Create(uploadUrl);
             if ((bool)_uploadFilesStateTable[file])
             {//覆盖
                 _uploadRequest.Method = WebRequestMethods.Ftp.UploadFile;
                 _currLength = 0;
             }
             else _uploadRequest.Method = _currLength == 0 ? WebRequestMethods.Ftp.UploadFile : WebRequestMethods.Ftp.AppendFile; 
             _uploadRequest.Credentials = new NetworkCredential(this.UserName, this.Password);
             _uploadRequest.Proxy = null;
             _uploadRequest.KeepAlive = false;
             _uploadRequest.BeginGetRequestStream(new AsyncCallback(TransFile), file);
         }
         return true;
     }
     catch (Exception e)
     {
         _result = e.Message;
         return false;
     }
 }