FTP gets file list error

  • Thread starter Thread starter lctk
  • Start date Start date
L

lctk

Guest
private string[] GetAllList(string url)
{
List<string> list = new List<string>();
FtpWebRequest req = (FtpWebRequest)WebRequest.Create(new Uri(url));
req.Credentials = new NetworkCredential(ftpPassword, ftpPassword);
req.Method = WebRequestMethods.Ftp.ListDirectory;
req.UseBinary = true;
req.UsePassive = false;
try
{
using (FtpWebResponse res = (FtpWebResponse)req.GetResponse())
{
using (StreamReader sr = new StreamReader(res.GetResponseStream()))
{
string s;
while ((s = sr.ReadLine()) != null)
{
list.Add(s);
}
}
}
}
catch (Exception ex)
{
throw (ex);
}
return list.ToArray();
}

Use the above method to

s = sr.ReadLine()

The error message prompts the host to forcibly close an existing connection, and the browser can input the path to obtain a list of files in the directory. How to solve this problem?


please verify my account

Continue reading...
 
Back
Top