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


C# FtpWebResponse.Close方法代码示例

本文整理汇总了C#中System.Net.FtpWebResponse.Close方法的典型用法代码示例。如果您正苦于以下问题:C# FtpWebResponse.Close方法的具体用法?C# FtpWebResponse.Close怎么用?C# FtpWebResponse.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.FtpWebResponse的用法示例。


在下文中一共展示了FtpWebResponse.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: createDirectory

 /* Create a New Directory on the FTP Server */
 public bool createDirectory(string newDirectory)
 {
     bool result = true;
      try
      {
     /* Create an FTP Request */
     ftpRequest = (FtpWebRequest)WebRequest.Create(host + "/" + newDirectory);
     /* Log in to the FTP Server with the User Name and Password Provided */
     ftpRequest.Credentials = new NetworkCredential(user, pass);
     /* 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.MakeDirectory;
     /* Establish Return Communication with the FTP Server */
     ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
     /* Resource Cleanup */
     ftpResponse.Close();
     ftpRequest = null;
      }
      catch (Exception ex)
      {
     StockLog.Write(ex.ToString());
     result = false;
      }
      return result;
 }
开发者ID:dadelcarbo,项目名称:StockAnalyzer,代码行数:29,代码来源:StockFTP.cs

示例2: copyToServer

        public bool copyToServer(string remote, string local, string logPath)
        {
            bool success = false;
//            try
//            {
                ftpRequest = (FtpWebRequest)WebRequest.Create(host + remote);
                ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
                ftpRequest.Credentials = netCreds;

                byte[] b = File.ReadAllBytes(local);

                ftpRequest.ContentLength = b.Length;
                using (Stream s = ftpRequest.GetRequestStream())
                {
                    s.Write(b, 0, b.Length);
                }

                ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
                // check was successful
                if (ftpResponse.StatusCode == FtpStatusCode.ClosingData)
                {
                    success = true;
                    logResult(remote, host, user, logPath);
                }
                ftpResponse.Close();
                
/*            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.Message);
            }*/
            return success;
        }
开发者ID:keltie21,项目名称:PAXperiments,代码行数:33,代码来源:FTPconnection.cs

示例3: DownloadFile

        public void DownloadFile(string remoteFile, string localFile)
        {
            // Создаем FTP Request
            ftpRequest = (FtpWebRequest)FtpWebRequest.Create(String.Format("{0}/{1}", host, remoteFile));
            // Инициализируем сетевые учетные данные
            ftpRequest.Credentials = new NetworkCredential(user, pass);

            ftpRequest.UseBinary = true;
            ftpRequest.UsePassive = true;
            ftpRequest.KeepAlive = true;

            // Задаем команду, которая будет отправлена на FTP-сервер
            ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
            ftpRequest.Timeout = TIMEOUT;
            // Ответ FTP-сервера
            ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
            // Возвращаем поток данных
            ftpStream = ftpResponse.GetResponseStream();
            // Создаем локальный файл
            FileStream localFileStream = new FileStream(localFile, FileMode.Create);
            // Пишем в файл
            ftpStream.CopyTo(localFileStream);

            localFileStream.Close();
            ftpStream.Close();
            ftpResponse.Close();
            ftpRequest = null;
        }
开发者ID:altaricka,项目名称:vDesign,代码行数:28,代码来源:FTPClient.cs

示例4: VerificaSeExiste

        public bool VerificaSeExiste(string destinfilepath, string ftphost, string ftpfilepath, string user, string pass)
        {
            ftpRequest = (FtpWebRequest)FtpWebRequest.Create("ftp://" + ftphost + "//" + ftpfilepath);

            ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;

            ftpRequest.Credentials = new NetworkCredential(user, pass);

            ftpRequest.UseBinary = true;
            ftpRequest.UsePassive = true;
            ftpRequest.KeepAlive = true;

            try {
                ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
                ftpResponse.Close();                
                ftpRequest = null;
                return true;
            }
            catch (Exception exc)
            {
                this.sErro = exc.Message;                
                return false;
            }
             
        }
开发者ID:prasist,项目名称:wb20,代码行数:25,代码来源:ClasseFtp.cs

示例5: createDirectory

 /* Create a New Directory on the FTP Server */
 public static void createDirectory(Data.RemoteServer data, string newDirectory)
 {
     /* Create an FTP Request */
     ftpRequest = (FtpWebRequest)WebRequest.Create(data.adress + newDirectory);
     /* 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.MakeDirectory;
     /* Establish Return Communication with the FTP Server */
     ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
     /* Resource Cleanup */
     ftpResponse.Close();
     ftpRequest = null;
 }
开发者ID:almaddy95,项目名称:MinecraftServerManager,代码行数:19,代码来源:Ftp.cs

示例6: delete

 /* Delete File */
 public void delete(string deleteFile)
 {
     /* Create an FTP Request */
     ftpRequest = (FtpWebRequest)WebRequest.Create(host + "/" + deleteFile);
     /* Log in to the FTP Server with the User Name and Password Provided */
     ftpRequest.Credentials = new NetworkCredential(user, pass);
     /* 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.DeleteFile;
     /* Establish Return Communication with the FTP Server */
     ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
     /* Resource Cleanup */
     ftpResponse.Close();
     ftpRequest = null;
 }
开发者ID:simul,项目名称:cruise_control,代码行数:19,代码来源:Ftp.cs

示例7: download

 /* Download File */
 public void download(string remoteFile, string localFile)
 {
     try
     {
         /* Create an FTP Request */
         ftpRequest = (FtpWebRequest)FtpWebRequest.Create(host + "/" + remoteFile);
         /* Log in to the FTP Server with the User Name and Password Provided */
         ftpRequest.Credentials = new NetworkCredential(user, pass);
         /* 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 */
         FileStream localFileStream = new FileStream(localFile, FileMode.Create);
         /* Buffer for the Downloaded Data */
         byte[] byteBuffer = new byte[bufferSize];
         int bytesRead = ftpStream.Read(byteBuffer, 0, bufferSize);
         /* Download the File by Writing the Buffered Data Until the Transfer is Complete */
         try
         {
             while (bytesRead > 0)
             {
                 localFileStream.Write(byteBuffer, 0, bytesRead);
                 bytesRead = ftpStream.Read(byteBuffer, 0, bufferSize);
             }
         }
         catch (Exception ex) { Console.WriteLine(ex.ToString()); }
         /* Resource Cleanup */
         localFileStream.Close();
         ftpStream.Close();
         ftpResponse.Close();
         ftpRequest = null;
     }
     catch (Exception ex) { Console.WriteLine(ex.ToString()); }
     return;
 }
开发者ID:minikie,项目名称:test,代码行数:43,代码来源:FTPConnector.cs

示例8: Delete

        /* Delete File */
        public void Delete(string deleteFile)
        {
            try
            {
                ftpRequest = (FtpWebRequest)WebRequest.Create(host + "/" + deleteFile);
                ftpRequest.Credentials = new NetworkCredential(user, pass);

                ftpRequest.UseBinary = true;
                ftpRequest.UsePassive = true;
                ftpRequest.KeepAlive = true;
                ftpRequest.Method = WebRequestMethods.Ftp.DeleteFile;

                ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();

                ftpResponse.Close();
                ftpRequest = null;
            }
            catch (Exception ex) { Console.WriteLine(ex.ToString()); }
            return;
        }
开发者ID:obritto,项目名称:FTPApp,代码行数:21,代码来源:Ftp.cs

示例9: createRemoteDirectory

        // Create Directory
        public void createRemoteDirectory(string newDirectory)
        {
            try
            {
                ftpRequest = (FtpWebRequest)WebRequest.Create(host + "/" + newDirectory);
                ftpRequest.Credentials = new NetworkCredential(user,pass);
                ftpRequest.UseBinary = true;
                ftpRequest.UsePassive = true;
                ftpRequest.KeepAlive = true;

                ftpRequest.Method = WebRequestMethods.Ftp.MakeDirectory;

                ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();

                ftpResponse.Close();
                ftpRequest = null;
            }
            catch(Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
开发者ID:CptTremendous,项目名称:FTPClient,代码行数:23,代码来源:Ftp.cs

示例10: DescargaArchivo

        public string DescargaArchivo(string ArchivoFTP, string ArchivoLocal)
        {
            try
            {
                ftpRequest = (FtpWebRequest)FtpWebRequest.Create(Direccion + "/" + ArchivoFTP);
                ftpRequest.Credentials = new NetworkCredential(Usuario, Password);
                ftpRequest.UseBinary = true;
                ftpRequest.UsePassive = true;
                ftpRequest.KeepAlive = true;

                Console.WriteLine("Iniciando proceso de Descarga de Archivo.");
                ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
                ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
                ftpStream = ftpResponse.GetResponseStream();
                FileStream ArchivoDescargado = new FileStream(ArchivoLocal, FileMode.Create);
                byte[] byteBuffer = new byte[2048];
                int bytesRead = ftpStream.Read(byteBuffer, 0, 2048);

                while (bytesRead > 0)
                {
                    ArchivoDescargado.Write(byteBuffer, 0, bytesRead);
                    bytesRead = ftpStream.Read(byteBuffer, 0, 2048);
                }

                Console.WriteLine("Proceso de Descarga Finalizado.");
                EliminarArchivo(ArchivoFTP);
                ArchivoDescargado.Close();
                ftpStream.Close();
                ftpResponse.Close();
                ftpRequest = null;
                return "Exito";
            }
            catch (Exception)
            {
                Console.WriteLine("No se encuentra el archivo para descargar");
                return "Error";
            }
        }
开发者ID:RamonCorrea,项目名称:RescateMarcasKarthus,代码行数:38,代码来源:FTP.cs

示例11: MakeDirectory

 /// <summary>
 /// 创建文件夹
 /// </summary>
 public void MakeDirectory()
 {
     ftpRequest.Method = WebRequestMethods.Ftp.MakeDirectory;
     try
     {
         response = (FtpWebResponse)ftpRequest.GetResponse();
     }
     catch (Exception ex)
     {
         if (ex.Message.IndexOf("550") < 0)
         {
             throw ex;
         }
         //throw ex;
     }
     finally
     {
         if (response != null)
         {
             response.Close();
         }
     }
 }
开发者ID:lxh2014,项目名称:gigade-net,代码行数:26,代码来源:FTP.cs

示例12: Delete

 /* Delete File */
 public void Delete(string deleteFile)
 {
     try
     {
         /* Create an FTP Request */
         _ftpRequest = (FtpWebRequest)WebRequest.Create(_host + "/" + deleteFile);
         /* Log in to the FTP Server with the User Name and Password Provided */
         _ftpRequest.Credentials = new NetworkCredential(_user, _pass);
         /* 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.DeleteFile;
         /* Establish Return Communication with the FTP Server */
         _ftpResponse = (FtpWebResponse)_ftpRequest.GetResponse();
         /* Resource Cleanup */
         _ftpResponse.Close();
         _ftpRequest = null;
     }
     catch (Exception ex) { Console.WriteLine(ex.ToString()); }
     return;
 }
开发者ID:pensacola1989,项目名称:ftpAsync,代码行数:24,代码来源:Ftp.cs

示例13: delete

        // Delete File
        public void delete(string filePath)
        {
            try
            {
                ftpRequest = (FtpWebRequest)WebRequest.Create(host + "/" + filePath);

                ftpRequest.Credentials = new NetworkCredential(user, pass);
                ftpRequest.UseBinary = true;
                ftpRequest.UsePassive = true;
                ftpRequest.KeepAlive = true;

                ftpRequest.Method = WebRequestMethods.Ftp.DeleteFile;
                ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();

                ftpResponse.Close();
                ftpRequest = null;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return;
        }
开发者ID:CptTremendous,项目名称:FTPClient,代码行数:24,代码来源:Ftp.cs

示例14: DownloadFileFTP

        public bool DownloadFileFTP(string destinfilepath, string ftphost, string ftpfilepath, string user, string pass)
        {
            try
            {

                ftpRequest = (FtpWebRequest)FtpWebRequest.Create("ftp://" + ftphost + "//" + ftpfilepath);             
                ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
                ftpRequest.Credentials = new NetworkCredential(user, pass);             
                ftpRequest.UseBinary = true;
                ftpRequest.UsePassive = true;
                ftpRequest.KeepAlive = true;                             
                ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();             
                ftpStream = ftpResponse.GetResponseStream();                
                FileStream localFileStream = new FileStream(destinfilepath, FileMode.Create);
                
                byte[] byteBuffer = new byte[bufferSize];
                int bytesRead = ftpStream.Read(byteBuffer, 0, bufferSize);
                
                while (bytesRead > 0)
                {
                    localFileStream.Write(byteBuffer, 0, bytesRead);
                    bytesRead = ftpStream.Read(byteBuffer, 0, bufferSize);
                }
                
                localFileStream.Close();
                ftpStream.Close();
                ftpResponse.Close();
                ftpRequest = null;
                return true;

            }
            catch (Exception erro)
            {
                throw new Exception(erro.Message);                
            }
        }
开发者ID:prasist,项目名称:wb20,代码行数:36,代码来源:ClasseFtp.cs

示例15: lsSimple

        private string[] lsSimple(string dir)
        {
            try
            {
                ftpRequest = (FtpWebRequest)WebRequest.Create(String.Format(baseUrl, dir));
                ftpRequest.Credentials = new NetworkCredential(userName, password);
                ftpRequest.UseBinary = true;
                ftpRequest.UsePassive = true;
                ftpRequest.KeepAlive = true;
                ftpRequest.EnableSsl = true;

                ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;

                ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();

                ftpStream = ftpResponse.GetResponseStream();

                StreamReader ftpReader = new StreamReader(ftpStream);

                StringBuilder result = new StringBuilder();
                try
                {
                    string line = ftpReader.ReadLine();
                    while (line != null)
                    {
                        result.Append(line);
                        result.Append("\n");
                        line = ftpReader.ReadLine();
                    }
                    //remove extra \n
                    result.Remove(result.ToString().LastIndexOf('\n'), 1);
                    ftpReader.Close();
                    ftpStream.Close();
                    ftpResponse.Close();
                    ftpRequest = null;
                    return result.ToString().Split('\n');
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error reading file list.\n" + ex.ToString());
                    if (result != null)
                        result = null;
                    if (ftpReader != null)
                        ftpReader.Close();
                    if (ftpResponse != null)
                        ftpResponse.Close();
                    if (ftpRequest != null)
                        ftpRequest = null;
                    return new string[] { "" };
                }
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return new string[] { "" };
        }
开发者ID:sgpicone,项目名称:WhatUtil,代码行数:59,代码来源:FTP.cs


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