ftp : get list of files

Posted by Rohan on Stack Overflow See other posts from Stack Overflow or by Rohan
Published on 2012-10-11T09:22:45Z Indexed on 2012/10/11 9:37 UTC
Read the original article Hit count: 187

Filed under:
|

I am trying to get a list of files on FTP folder. The code was working when I ran it locally, but on deploying it I started receiving html instead of file name

            ArrayList fName = new ArrayList();
            try
            {
                StringBuilder result = new StringBuilder();

                //create the directory
                FtpWebRequest requestDir = (FtpWebRequest)FtpWebRequest.Create(new Uri(directory));
                requestDir.Method = WebRequestMethods.Ftp.ListDirectory;
                requestDir.Credentials = new NetworkCredential(FTP_USER_NAME, FTP_PASSWORD);
                requestDir.UsePassive = true;
                requestDir.UseBinary = true;
                requestDir.KeepAlive = false;
                requestDir.Proxy = null;
                FtpWebResponse response = (FtpWebResponse)requestDir.GetResponse();
                Stream ftpStream = response.GetResponseStream();
                StreamReader reader = new StreamReader(ftpStream, Encoding.ASCII);


                while (!reader.EndOfStream)
                {
                    fName.Add(reader.ReadLine().ToString());
                }

                response.Close();
                ftpStream.Close();
                reader.Close();

© Stack Overflow or respective owner

Related posts about c#

Related posts about ftp