从ftp c#的子文件夹下载文件 [英] download file from subfolders in ftp c#

查看:58
本文介绍了从ftp c#的子文件夹下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

im haseeb

我想从文件夹/子文件夹/<somefilename.extension>中下载文件.在ftp c#
中 ftp可以从根文件夹(即子文件夹)而不是子文件夹子文件夹在线下载文件
我该怎么做
你能给我发送一些代码,显示文件从ftp c#中的fron子文件夹下载吗? 生病的感谢您

hello

im haseeb

i want to download files from the folder/subfolder/<somefilename.extension> in ftp c#
ftp could online download files from the root folder i.e folder not from the child folder subfolder
how can i do that
can u plz send me some piece of code showing file download fron sub folder in ftp c#
ill be highly thankful to you

推荐答案

不是那样的.

您只需给出包含在子文件夹中的文件的路径,就可以
从子文件夹或任何文件夹层次结构下载文件.

请尝试以下示例.


It''s not like that.

You can just give path of the file contained in sub folder and you can
download the file from sub folder or any folder hierarchy.

Try following example.


// Get the object used to communicate with the server.
//Instead of ftp://www.contoso.com/test.htm you can try
//ftp://www.contoso.com/folder/test.htm or you can also try
//ftp://www.contoso.com/folder/subfolder/subfolder/test.htm

            FtpWebRequest request =    
(FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/test.htm");
            request.Method = WebRequestMethods.Ftp.DownloadFile;

            // This example assumes the FTP site uses anonymous logon.
            request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com");

            FtpWebResponse response = (FtpWebResponse)request.GetResponse();
    
            Stream responseStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(responseStream);
            Console.WriteLine(reader.ReadToEnd());

            Console.WriteLine("Download Complete, status {0}", response.StatusDescription);
    
            reader.Close();
            response.Close();




HTH




HTH


看看如何在C#中使用FTP:
.NET 2.0的FTP客户端库 [ C#FTP客户端库 [
Have a look at these of how to have FTP in C#:
An FTP client library for .NET 2.0[^]
C# FTP Client Library[^]


这篇关于从ftp c#的子文件夹下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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