问题如下:
我找到了一个解决方案,它可以列出 ftp 服务器根目录中的文件和目录。但我也需要目录的内容。我需要如何修改这个方法?
internal void ListFilesOnServer()
{
try
{
FtpWebRequest ftpwrq = (FtpWebRequest)WebRequest.Create(server);
ftpwrq.Credentials = new NetworkCredential(user,passw);
ftpwrq.Method = WebRequestMethods.Ftp.ListDirectory;
ftpwrq.KeepAlive = false;
FtpWebResponse fresponse = (FtpWebResponse)ftpwrq.GetResponse();
StreamReader sr = new StreamReader(fresponse.GetResponseStream());
StreamWriter sw = new StreamWriter(new FileStream("test.txt", FileMode.Create));
sw.WriteLine(sr.ReadToEnd());
sw.Close();
fresponse.Close();
sr.Close();
MessageBox.Show("Gotcha");
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}