.Net 下載 FTP 檔案 .Net 下載 FTP 檔案
  .NET       ez      2012-08-24

本篇利用 FtpWebRequest 下載 FTP 檔案:

        private static string FtpDownLoad(string url, string strUserName, string strPassword)
        {
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri(url));
            request.Method = WebRequestMethods.Ftp.DownloadFile;
            if (!String.IsNullOrEmpty(strUserName) && !String.IsNullOrEmpty(strPassword)) request.Credentials = new NetworkCredential(strUserName, strPassword);
            FtpWebResponse response = (FtpWebResponse)request.GetResponse();
            Stream responseStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(responseStream, Encoding.Default);
            return reader.ReadToEnd();
        }

標籤:   .NET

我要留言