public string[] GetFileList() { string[] downloadFiles; StringBuilder result = new StringBuilder(); WebResponse response = null; StreamReader reader = null; try { FtpWebRequest reqFTP; reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("uri")); reqFTP.UseBinary = true; reqFTP.Credentials = new NetworkCredential("Abc", "Abc"); reqFTP.Method = WebRequestMethods.Ftp.ListDirectory; reqFTP.Proxy = null; reqFTP.KeepAlive = false; reqFTP.UsePassive = false; response = reqFTP.GetResponse(); reader = new StreamReader(response.GetResponseStream()); string line = reader.ReadLine(); while (line != null) { result.Append(line); result.Append("\n"); line = reader.ReadLine(); } // to remove the trailing '\n' result.Remove(result.ToString().LastIndexOf('\n'), 1); return result.ToString().Split('\n'); } catch (Exception ex) { if (reader != null) { reader.Close(); } if (response != null) { response.Close(); } downloadFiles = null; WriteLog("Error at GetFileList :>" + ex.Message); return downloadFiles; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)