2017년 2월 27일 월요일

[C#] To download files on the FTP using WebClient class

Following example is to download guestbook.file on the FTP using WebClient class.
That FTP needs login. It's very simple example.
When you need more detail option, you can use HttpClient;
But HttpClient is supported on the .Net Framework 4.5.

-----------------------------------------------------------------------------------------------


using System.Net;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main()
        {
            WebClient wc = new WebClient { Proxy = null };
            wc.BaseAddress = "ftp://ftp.albahari.com";
            string username = "nutshell";
            string password = "oreilly";
            wc.Credentials = new NetworkCredential(username, password);

            wc.DownloadFile("guestbook.txt", @"d:\guestbook.txt");
        }
    }
}

댓글 없음:

댓글 쓰기