Click here to Skip to main content
15,900,589 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am in deep problems in handling ftp file in UNIX mode,here is the piece of code.

     public void GetFilesList(string FTPAddress, string username, string password)
         List<string> files = new List<string>();

             this.Text = "Connecting...";
             Application.DoEvents(); //test to change here

             //Create FTP request
             FtpWebRequest request = FtpWebRequest.Create(FTPAddress) as FtpWebRequest;
          //   System.Net.FtpWebRequest reqFTP; check here
            // reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + textServer.Text + "/" + textRemotePath.Text + "/" + file)); //check here

             request.Method = WebRequestMethods.Ftp.ListDirectory;
             request.Credentials = new NetworkCredential(username, password);
             request.UsePassive = true;//change here false
             request.UseBinary = true;
             request.KeepAlive = false;

             //Read the server's response
             this.Text = "Retrieving List...";
             Application.DoEvents(); // test to change here
             FtpWebResponse response = request.GetResponse() as FtpWebResponse;
             Stream responseStream = response.GetResponseStream();
             StreamReader reader = new StreamReader(responseStream);

             while (!reader.EndOfStream)
                 Application.DoEvents(); //test to change here

             responseStream.Close(); //redundant

         catch (Exception)
             MessageBox.Show("There was an error connecting to the FTP Server");
         username = string.Empty;
         password = string.Empty;
         if (files.Count != 0)
             listViewRemote.Items.Add(new ListViewItem(new string[2] { "..", "" }, 0));
             ListViewItem item;

             foreach (string file in files)
                 item = new ListViewItem(new String[2] { file.ToString(), file.Length.ToString() }, 1);
                 item.Tag = file;

               // listViewRemote.Items.Add(file);

I need only file name listing in list box that can be downloaded later, here full html file show in listbox and one thing i need ftp current directory that I have to show text box.
Any one please helm me, I am tired to trying myself.
Software Engineer
Updated 23-Oct-10 21:17pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900