本文整理匯總了C#中System.Net.FtpWebRequest.BeginGetRequestStream方法的典型用法代碼示例。如果您正苦於以下問題:C# FtpWebRequest.BeginGetRequestStream方法的具體用法?C# FtpWebRequest.BeginGetRequestStream怎麽用?C# FtpWebRequest.BeginGetRequestStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Net.FtpWebRequest
的用法示例。
在下文中一共展示了FtpWebRequest.BeginGetRequestStream方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: UploadNextFile
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: UploadFile
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;
}
}