本文整理汇总了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;
}
}