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


C# FtpWebRequest.GetResponse方法代码示例

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


在下文中一共展示了FtpWebRequest.GetResponse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

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

 public bool testConnection()
 {
     ftpRequest = (FtpWebRequest)WebRequest.Create(host);
     ftpRequest.Method = WebRequestMethods.Ftp.PrintWorkingDirectory;
     ftpRequest.Credentials = netCreds;
     if (ftpRequest.GetResponse() != null)
     {
         return true;
     }
     return false;
 }
开发者ID:keltie21,项目名称:PAXperiments,代码行数:11,代码来源:FTPconnection.cs

示例7: GetResponseString

 private string GetResponseString(FtpWebRequest rq)
 {
     var response = (FtpWebResponse)rq.GetResponse();
     string res;
     using (var responseStream = response.GetResponseStream())
     {
         using (var sr = new StreamReader(responseStream))
         {
             res = sr.ReadToEnd();
         }
     }
     return res;
 }
开发者ID:Buthrakaur,项目名称:FtpIntegrationTesting,代码行数:13,代码来源:Test.cs

示例8: UploadFiles

        public static bool UploadFiles(string filePath, Uri networkPath, NetworkCredential credentials)
        {
            bool resultUpload = false;
            System.Threading.Thread.Sleep(500);
            Console.WriteLine("\nInitializing Network Connection..");

            /* si potrebbe impostare da riga di comando il keep alive, la passive mode ed il network path */
            /* progress bar? */

                //request = (FtpWebRequest)WebRequest.Create(networkPath + @"/" + Path.GetFileName(filePath));
                request = (FtpWebRequest) WebRequest.Create(networkPath + @"/"  + Path.GetFileName(filePath));
                request.Method = WebRequestMethods.Ftp.UploadFile;
                request.UsePassive = true;
                request.KeepAlive = false; /* è necessario? */
                request.Credentials = credentials;

            /* è necessario impostare la protezione ssl? */
            //request.EnableSsl = true;
                using (Stream requestStream = request.GetRequestStream())
                {

                    System.Threading.Thread.Sleep(500);
                    Console.WriteLine("\nReading the file to transfer...");
                    using (StreamReader sourceStream = new StreamReader(filePath))
                    {
                        byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
                        sourceStream.Close();
                        request.ContentLength = fileContents.Length;

                        System.Threading.Thread.Sleep(500);
                        Console.WriteLine("\nTransferring the file..");

                        requestStream.Write(fileContents, 0, fileContents.Length);
                        requestStream.Close();
                    }
                }

            Console.WriteLine("\nClosing connection...");

            using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
            {
                System.Threading.Thread.Sleep(500);
                Console.WriteLine("\nUpload of " + Path.GetFileName(filePath) + " file complete.");
                Console.WriteLine("Request status: {0}", response.StatusDescription);
                if(response.StatusDescription.Equals("226 Transfer complete.\r\n"))
                    resultUpload = true;
                response.Close();
            }

            return resultUpload;
        }
开发者ID:sicil1ano,项目名称:FtpUploader,代码行数:51,代码来源:FtpHelperSingleFile.cs

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

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

示例12: UploadFiles

        /* 1st version of the method UploadFiles, used to upload one file.  (KeepAlive = false) */
        public static bool UploadFiles(string filePath, string networkPath, NetworkCredential credentials)
        {
            bool resultUpload = false;
            System.Threading.Thread.Sleep(500);
            Console.WriteLine("\nInitializing Network Connection..");

            request = (FtpWebRequest)WebRequest.Create(UriPath(networkPath) + Path.GetFileName(filePath));
            request.Method = WebRequestMethods.Ftp.UploadFile;
            request.UsePassive = true;
            request.KeepAlive = false;
            request.Credentials = credentials;

            /* set ssl protection? */
            //request.EnableSsl = true;
            using (Stream requestStream = request.GetRequestStream())
            {

                System.Threading.Thread.Sleep(500);
                Console.WriteLine("\nReading the file " + Path.GetFileName(filePath) + "...");
                using (StreamReader sourceStream = new StreamReader(filePath))
                {
                    byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
                    sourceStream.Close();
                    request.ContentLength = fileContents.Length;

                    requestStream.Write(fileContents, 0, fileContents.Length);
                    requestStream.Close();
                }
            }

            using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
            {
                System.Threading.Thread.Sleep(500);
                Console.WriteLine("\nUpload of " + Path.GetFileName(filePath) + " file complete.");
                Console.WriteLine("Request status: {0}", response.StatusDescription);
                if (response.StatusDescription.Equals("226 Transfer complete.\r\n"))
                    resultUpload = true;
                response.Close();

            }

            Console.WriteLine("\nClosing connection to {0}...", string.Format("ftp://{0}", networkPath));
            return resultUpload;
        }
开发者ID:sicil1ano,项目名称:FtpUploader,代码行数:45,代码来源:FtpHelper.cs

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

示例14: DownloadNewVersion

        private static void DownloadNewVersion()
        {
            request = (FtpWebRequest)WebRequest.Create(versionsInfo.ServerUrl + serverVersion.Version + ".zip");
            request.Method = WebRequestMethods.Ftp.DownloadFile;
            request.Credentials = credentials;

            FtpWebResponse response = (FtpWebResponse)request.GetResponse();
            Console.WriteLine("Downloading file to : " + versionsInfo.DownloadLocation + serverVersion.Version.ToString() + ".zip");
            Stream responseStream = response.GetResponseStream();
            using (var localFileStream =
                new FileStream(Path.Combine(versionsInfo.DownloadLocation, serverVersion.Version.ToString() + ".zip"), FileMode.Create))
            {
                while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    totalBytesRead += bytesRead;
                    localFileStream.Write(buffer, 0, bytesRead);
                }
            }
        }
开发者ID:Ruandv,项目名称:Training,代码行数:19,代码来源:Program.cs

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


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