本文整理汇总了C#中System.Net.FtpWebRequest.Abort方法的典型用法代码示例。如果您正苦于以下问题:C# FtpWebRequest.Abort方法的具体用法?C# FtpWebRequest.Abort怎么用?C# FtpWebRequest.Abort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.FtpWebRequest
的用法示例。
在下文中一共展示了FtpWebRequest.Abort方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: worker_DoWork
private void worker_DoWork(object sender, DoWorkEventArgs e)
{
/* Create an FTP Request */
ftpRequest = (FtpWebRequest)FtpWebRequest.Create(data.adress + "/" + remoteFile);
/* Log in to the FTP Server with the User Name and Password Provided */
ftpRequest.Credentials = new NetworkCredential(data.login, data.password);
/* When in doubt, use these options */
ftpRequest.UseBinary = true;
ftpRequest.UsePassive = true;
ftpRequest.KeepAlive = true;
/* Specify the Type of FTP Request */
ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
/* Establish Return Communication with the FTP Server */
ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
/* Get the FTP Server's Response Stream */
ftpStream = ftpResponse.GetResponseStream();
/* Open a File Stream to Write the Downloaded File */
Directory.CreateDirectory(Path.GetDirectoryName(localFile));
localFileStream = new FileStream(localFile, FileMode.Create);
/* Buffer for the Downloaded Data */
byte[] byteBuffer = new byte[bufferSize];
int bytesRead = ftpStream.Read(byteBuffer, 0, bufferSize);
int totalBytesRead = bytesRead;
/* Download the File by Writing the Buffered Data Until the Transfer is Complete */
while (bytesRead > 0)
{
if (cancel)
{
localFileStream.Close();
ftpRequest.Abort();
ftpStream.Close();
ftpResponse.Close();
ftpRequest = null;
ftpResponse = null;
ftpStream = null;
localFileStream = null;
e.Cancel = true;
return;
}
localFileStream.Write(byteBuffer, 0, bytesRead);
bytesRead = ftpStream.Read(byteBuffer, 0, bufferSize);
totalBytesRead += bytesRead;
double progress = totalBytesRead * 100.0 / fileSize;
WorkerState state = new WorkerState(fileSize, totalBytesRead);
worker.ReportProgress((int)progress, state);
}
/* Resource Cleanup */
localFileStream.Close();
ftpStream.Close();
ftpResponse.Close();
ftpRequest = null;
}
示例2: DownloadDll
private bool DownloadDll(Stream stream, FtpWebRequest reqFtp, string newVersion, string newName, out string newFileLocation)
{
if (Directory.Exists(Furniture.Helpers.LocalAccounts.modelPathResult.Replace("_SWLIB_", "_SWLIB_BACKUP")))
{
string warnMessage =
@"�������� ���� �������� ! � ������ ������ ��� �������������� ������� ������� ��������� ������, ��������� ������� � ��������� ����������� ������ ����� ���� ��� ! � ������ ������� �������������� ������� (���� ����\��������)�������� ����������� ������ � �� ����������� ���������,���������� � ��������� ������������ ������� �� ������������ � ��������� ������������ ������� ����������.";
MessageBox.Show(warnMessage, "��������!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
stream.Close();
reqFtp.Abort();
//long size = GetSizeForFurnitureDll(Properties.Settings.Default.FurnFtpPath + newVersion);
long size = GetSizeForFurnitureDll(Furniture.Helpers.FtpAccess.resultFtp + newVersion);
UserProgressBar pb;
SwApp.GetUserProgressBar(out pb);
FileStream fileStream = null;
try
{
fileStream = new FileInfo(newName).Create();
}
catch (Exception)
{
MessageBox.Show("�� �������� ������� ���� " + newName + "�������� ��-�� ���� ��� ��� ��� ���� ����� �������.");
}
var wc = new WebClient { Credentials = new NetworkCredential(Properties.Settings.Default.FurnFtpName, Properties.Settings.Default.FurnFtpPass) };
var str =
//wc.OpenRead(Properties.Settings.Default.FurnFtpPath + newVersion + "/Furniture.dll");
wc.OpenRead(Furniture.Helpers.FtpAccess.resultFtp + newVersion + "/Furniture.dll");
const int bufferSize = 1024;
var z = (int)(size / bufferSize);
var buffer = new byte[bufferSize];
int readCount = str.Read(buffer, 0, bufferSize);
pb.Start(0, z, "���������� ���������");
int i = 0;
while (readCount > 0)
{
fileStream.Write(buffer, 0, readCount);
readCount = str.Read(buffer, 0, bufferSize);
pb.UpdateProgress(i);
i++;
}
pb.End();
fileStream.Close();
wc.Dispose();
newFileLocation = newName;
return true;
}