2

Im trying to make a program that lets you check the availibility of a specific file extention on that ftp server and then sort the ones out that have the files on.

this is how i tried to do it so far:

string path;
path = "ftp://" + textBox1.Text + "/";
string[] files = System.IO.Directory.GetFiles(path, "*.txt", SearchOption.AllDirectories);
2
  • 2
    don't get what ur asking for
    – MichaC
    Nov 17, 2013 at 17:35
  • The System.IO.Directory et al classes are for SMB only (IIRC), not for FTP.
    – Uwe Keim
    Nov 17, 2013 at 18:33

1 Answer 1

3
FtpWebRequest ftpRequest = 
    (FtpWebRequest)WebRequest.Create("ftp://ftp.freebsd.org/pub/FreeBSD/");

ftpRequest.Credentials = new NetworkCredential("anonymous", "k3rnel31@k.com");
ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse();
StreamReader streamReader = new StreamReader(response.GetResponseStream());

List<string> filestxt = new List<string>();

string line = streamReader.ReadLine();
while (!string.IsNullOrEmpty(line))
{
    if (line.Contains(".txt")) 
    {
        MessageBox.Show(line); 
        line = streamReader.ReadLine();
        filestxt.Add(line);
    } 
    else 
    { 
        line = streamReader.ReadLine(); 
    }
}

streamReader.Close();
1
  • @user3002135 i have fixed some errors now it works perfect ! check the edit answer
    – Hichem
    Nov 17, 2013 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.