如何通过C#从ftp使用HttpWebRequest下载文件 [英] How to download a file using HttpWebRequest from ftp through c#

查看:83
本文介绍了如何通过C#从ftp使用HttpWebRequest下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过使用http Web请求从ftp下载文件
请发送源代码给我,如果可能的话.

is it possible that we can download a file from ftp by using http web request
please send me source code if it is possible

推荐答案

现在看来似乎不合逻辑了吗?通过HTPP协议请求的FTP协议请求.

您可以查看 FtpWebRequest [
Well that would not seem logical now would it? An FTP protocal request through a HTPP protocol request.

You could look into FtpWebRequest[]

The following code example demonstrates downloading a file from an FTP server by using the WebClient class.

public static bool DisplayFileFromServer(Uri serverUri)
{
   // The serverUri parameter should start with the ftp:// scheme.
   if (serverUri.Scheme != Uri.UriSchemeFtp)
   {
      return false;
   }

   // Get the object used to communicate with the server.
   WebClient request = new WebClient();
    
   // This example assumes the FTP site uses anonymous logon.
   request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com");

   try 
   {
      byte [] newFileData = request.DownloadData (serverUri.ToString());
      string fileString = System.Text.Encoding.UTF8.GetString(newFileData);
      Console.WriteLine(fileString);
   }
   catch (WebException e)
   {
      Console.WriteLine(e.ToString());
   }

   return true;
}


这篇关于如何通过C#从ftp使用HttpWebRequest下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆