How to list directory content of an FTP server

private string[] GetAnnouncementFileNames(string ftpFolderPath, string ftpUsername, string ftpPassword)
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpFolderPath);
            request.Method = WebRequestMethods.Ftp.ListDirectory;
            request.Credentials = new NetworkCredential(ftpUsername, ftpPassword);

            using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
                using (Stream responseStream = response.GetResponseStream())
                    using (StreamReader reader = new StreamReader(responseStream))
                        var fileNameString = reader.ReadToEnd();
                        var fileNames = fileNameString.Split(new string[] { Environment.NewLine },
                        return fileNames;

Author: Harshani Nawarathna

Sri Lankan woman in Computing

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s