当前位置: 首页>>代码示例>>C#>>正文


C# FtpWebRequest.Abort方法代码示例

本文整理汇总了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;
        }
开发者ID:almaddy95,项目名称:MinecraftServerManager,代码行数:53,代码来源:FtpDownloader.cs

示例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;
        }
开发者ID:digger1985,项目名称:MyCode,代码行数:47,代码来源:SwAddin.cs


注:本文中的System.Net.FtpWebRequest.Abort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。