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

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

         try
         {
             //Optional
             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
                 files.Add(reader.ReadLine());
             }

             //Clean-up
             reader.Close();
             responseStream.Close(); //redundant
             response.Close();

         }
         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.Clear();
             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(item);

               // 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.
Mahmud
Software Engineer
Posted
Updated 23-Oct-10 21:17pm
v2

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