创建FtpWebRequest对象:
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://" + Fcom.Text + "/");
指定数据传输类型:
request.UseBinary = true;
连接认证:
request.Credentials = new NetworkCredential(Acom.Text, Pcom.Text);
获得文件和文件夹信息:
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
获得ftp响应数据:
FtpWebResponse response = (FtpWebResponse)request.GetResponse(); Stream responseStream = response.GetResponseStream(); StreamReader readStream = new StreamReader(responseStream, System.Text.Encoding.Default);
显示数据:
string dataString = readStream.ReadToEnd();
如果碰到Proxy代理情况,简单处理方法就是:
request.Proxy = null;