• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Net.FtpWebResponse类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



FtpWebResponse类属于System.Net命名空间,在下文中一共展示了FtpWebResponse类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: DownloadFtp

        /// <summary>
        /// 连接FTP的方法
        /// </summary>
        /// <param name="ftpuri">ftp服务器地址,端口</param>
        /// <param name="ftpUserID">用户名</param>
        /// <param name="ftpPassword">密码</param>
        public DownloadFtp(string ftpuri, string ftpUserID, string ftpPassword)
        {
            // 根据uri创建FtpWebRequest对象
              ft = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpuri));
              // ftp用户名和密码
              ft.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
              ft.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
             fr = (FtpWebResponse)ft.GetResponse();
              stream = fr.GetResponseStream();
              ////二进制文件读入
              //if (!fr.ContentType.ToLower().StartsWith("text/"))
              //{
              //    SaveBinaryFile(fr);
              //}
              ////文本文件
              //else
              //{
              string buffer = "", line;
              StreamReader reader = new StreamReader(stream);
              while ((line = reader.ReadLine()) != null)
              {
                  buffer += line + "\r\n";
              }

              //装入整个文件之后,接着就要把它保存为文本文件。
              SaveTextFile(buffer);
              //}
        }
开发者ID:kiichi7,项目名称:Search-Engine,代码行数:34,代码来源:DownloadFtp.cs


示例2: 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


示例3: 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


示例4: 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


示例5: 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


示例6: ListDirectory

        public string[] ListDirectory(string directory)
        {

            ftpRequest = (FtpWebRequest)FtpWebRequest.Create(String.Format("{0}/{1}", host, directory));

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

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

            ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
            ftpRequest.Timeout = TIMEOUT;

            ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();

            ftpStream = ftpResponse.GetResponseStream();

            StreamReader ftpReader = new StreamReader(ftpStream);

            string directoryRaw = null;

            try
            {
                while (ftpReader.Peek() != -1)
                {
                    //TODO: выдергиваем имя файла, доделать...
                    directoryRaw += ftpReader.ReadLine().Split(' ').Last() + "|";
                }
            }
            catch
            {
            }

            ftpReader.Close();
            ftpStream.Close();
            ftpResponse.Close();
            ftpRequest = null;

            try
            {
                string[] directoryList = directoryRaw.Split("|".ToCharArray());
                return directoryList;
            }
            catch
            {
            }

            return new string[] { };
        }
开发者ID:altaricka,项目名称:vDesign,代码行数:50,代码来源:FTPClient.cs


示例7: WriteResponseToFile

        private void WriteResponseToFile(string destPath, FtpWebResponse response, Stream responseStream)
        {
            FileStream writer = new FileStream(destPath, FileMode.Create);

            long length = response.ContentLength;
            int bufferSize = 2048;
            int readCount;
            byte[] buffer = new byte[bufferSize];

            readCount = responseStream.Read(buffer, 0, bufferSize);
            while (readCount > 0)
            {
                writer.Write(buffer, 0, readCount);
                readCount = responseStream.Read(buffer, 0, bufferSize);
            }
            writer.Close();
        }
开发者ID:jcere,项目名称:Telemetry,代码行数:17,代码来源:Collection.cs


示例8: SaveBinaryFile

        //二进制文件存储方法
        protected void SaveBinaryFile(FtpWebResponse response)
        {
            byte[] buffer = new byte[1024];
              string filename = convertFilename(response.ResponseUri);
              Stream outStream = File.Create(filename);
              Stream inStream = response.GetResponseStream();

              int l;
              do
              {
              l = inStream.Read(buffer, 0,
              buffer.Length);
              if (l > 0)
                  outStream.Write(buffer, 0, l);
              } while (l > 0);
              outStream.Close();
        }
开发者ID:kiichi7,项目名称:Search-Engine,代码行数:18,代码来源:DownloadFtp.cs


示例9: 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


示例10: 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


示例11: Download

 /// <summary>
 /// 下載FTP檔案
 /// 存儲至Client端桌面
 /// </summary>
 /// <param name="FileName">要下載的檔案名稱</param>
 /// <returns></returns>
 public static bool Download(string FileName)
 {
     bool result = false;
     string LocalFile = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\" + FileName;
     try
     {
         Uri FtpPath = new Uri(uriServer + FileName);
         ftpRequest = (FtpWebRequest)WebRequest.Create(FtpPath);
         ftpRequest.Credentials = new NetworkCredential(UserName,Password);
         ftpRequest.UseBinary = true;
         ftpRequest.UsePassive = true;
         ftpRequest.KeepAlive = true;
         ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
         ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
         ftpStream = ftpResponse.GetResponseStream();
         ftpFileStream = new FileStream(LocalFile, FileMode.Create);
         int BufferSize = 2048;
         byte[] byteBuffer = new byte[BufferSize];
         int bytesRead = ftpStream.Read(byteBuffer, 0, BufferSize);
         try
         {
             while (bytesRead > 0)
             {
                 ftpFileStream.Write(byteBuffer, 0, bytesRead);
                 bytesRead = ftpStream.Read(byteBuffer, 0, BufferSize);
             }
             result = true;
         }
         catch (Exception ex)
         {
             sysMessage.SystemEx(ex.Message);
         }
         ftpFileStream.Close();
         ftpStream.Close();
         ftpResponse.Close();
         ftpRequest = null;
     }
     catch (Exception ex)
     {
         sysMessage.SystemEx(ex.Message);
     }
     return result;
 }
开发者ID:coreychen71,项目名称:EWPCB-Project,代码行数:49,代码来源:ConnFTP.cs


示例12: 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


示例13: 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


示例14: EliminarArchivo

 public void EliminarArchivo(string ArchivoEliminar)
 {
     try
     {
         Console.WriteLine("Iniciando proceso de eliminacion de archivo iniciado.");
         ftpRequest = (FtpWebRequest)FtpWebRequest.Create(Direccion + "/" + ArchivoEliminar);
         ftpRequest.Credentials = new NetworkCredential(Usuario, Password);
         ftpRequest.UseBinary = true;
         ftpRequest.UsePassive = true;
         ftpRequest.KeepAlive = true;
         ftpRequest.Method = WebRequestMethods.Ftp.DeleteFile;
         ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
         Console.WriteLine("Archivo eliminado correctamente.");
         ftpResponse.Close();
         ftpRequest = null;
     }
     catch (Exception)
     {
         Console.WriteLine("No se encuentra el archivo a eliminar");
     }
 }
开发者ID:RamonCorrea,项目名称:RescateMarcasKarthus,代码行数:21,代码来源:FTP.cs


示例15: DownloadFile

        /// <summary>
        /// 下载文件
        /// </summary>
        /// <param name="remoteFile"></param>
        /// <returns></returns>
        public byte[] DownloadFile(string remoteFile)
        {
            this.Connect("ftp://" + this._serverIP + "/" + remoteFile);
            this.ftpRequest.Method = "RETR";

            using (this.ftpResponse = (FtpWebResponse)this.ftpRequest.GetResponse())
            {
                using (this.ftpStream = this.ftpResponse.GetResponseStream())
                {
                    byte[] byteBuffer = new byte[this.bufferSize];
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        for (int bytesRead = this.ftpStream.Read(byteBuffer, 0, this.bufferSize); bytesRead > 0; bytesRead = this.ftpStream.Read(byteBuffer, 0, this.bufferSize))
                        {
                            memoryStream.Write(byteBuffer, 0, bytesRead);
                        }
                        return memoryStream.Length > 0 ? memoryStream.ToArray() : null;
                    }
                }
            }
        }
开发者ID:Yowe,项目名称:src,代码行数:26,代码来源:MyFtp.cs


示例16: 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


示例17: listFiles

        //Sorts the files and only shows the files you want.
        public List<String> listFiles(FtpWebResponse files, Boolean showAllFiles)
        {
            Stream responseStream = files.GetResponseStream();
            StreamReader reader = new StreamReader(responseStream);
            String filesFolders = reader.ReadToEnd();

            List<String> fileArray = filesFolders.Split('\n').ToList<String>();
            List<String> newList = new List<string>();

            if (!showAllFiles)
            {
                foreach (String s in fileArray)
                {
                    if (s.Contains(".mp3") || s.StartsWith("d")) //Feel free to add the filetypes you like.
                    {
                        if (s.Length > 0)
                        {
                            Char[] c = s.ToCharArray();
                            for (int i = 0; i < c.Length; i++)
                            {
                                if (c[i] == ':')
                                {
                                    newList.Add(s.Substring(i + 4));
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (String s in fileArray)
                {
                    newList.Add(s); //Adds all directorydetails
                }
            }
            newList.Sort();
            return newList;
        }
开发者ID:hulvei3,项目名称:MusicStreamer,代码行数:40,代码来源:FtpWebRequestTest.cs


示例18: 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


示例19: 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


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Net.HttpListener类代码示例发布时间:2022-05-26
下一篇:
C# Net.FtpWebRequest类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap