//---------------------------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); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)