FtpWebRequest Request = (FtpWebRequest)WebRequest.Create(Address);
Request.Method = WebRequestMethods.Ftp.ListDirectory; //列表
Request.Credentials = new NetworkCredential(user, pass);
FtpWebResponse Response = (FtpWebResponse)Request.GetResponse();
Stream ResponseStream = Response.GetResponseStream();
StreamReader Reader = new StreamReader(ResponseStream);
lstWelcome.Items.Add(Response.BannerMessage);
lstWelcome.Items.Add(Response.WelcomeMessage);
while (!Reader.EndOfStream)//读取列表
{
lstFiles.Items.Add(Reader.ReadLine());
}
Response.Close();
ResponseStream.Close();
Reader.Close();
MSDN参考:
http://msdn.microsoft.com/zh-cn/library/system.net.ftpwebrequest(VS.80).aspx