I use the codes below to retrieve files from an FTP site. It works on my computer, but it only returns HTML codes when I run it on another computer (I see that HTML is the web page codes when accessing FTP via a browser). What's wrong?
public String GetFilesAsString(string folder,string fileExtension) { StringBuilder result = new StringBuilder(); FtpWebRequest reqFTP; try { String ftpserver = ftp + folder+"/"; reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpserver)); reqFTP.UsePassive = false; reqFTP.UseBinary = true; reqFTP.Credentials = new NetworkCredential(username, password); reqFTP.Method = WebRequestMethods.Ftp.ListDirectory; FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8); string line = ""; while (reader.Peek()>-1) { line = reader.ReadLine(); Console.WriteLine(line);//**********HTML was wrote out here************* } if (result.ToString().LastIndexOf('\n') >= 0) result.Remove(result.ToString().LastIndexOf('\n'), 1); reader.Close(); response.Close(); return result.ToString(); } catch (Exception ex) { } return null; }

source share