Like me and everyone who reads this list, all the files from the online directory to the list?
This is the code for the local directory to be specified. I would like to know if there is a way to do this so that it connects to the FTP site and displays the files?
FolderBrowserDialog folderPicker = new FolderBrowserDialog(); if (folderPicker.ShowDialog() == DialogResult.OK) { ListView1.Items.Clear(); string[] files = Directory.GetFiles(folderPicker.SelectedPath); foreach (string file in files) { string fileName = Path.GetFileNameWithoutExtension(file); ListViewItem item = new ListViewItem(fileName); item.Tag = file; ListView1.Items.Add(item); } }
I used this code, but I can not get it to work so that it does not appear with an error, but does it not display files on the web server?
private void ConnectBtn_Click(object sender, EventArgs e) { ListDirectory(); } public string[] ListDirectory() { var list = new List<string>(); var request = createRequest(TxtServer.Text, WebRequestMethods.Ftp.ListDirectory); using (var response = (FtpWebResponse)request.GetResponse()) { using (var stream = response.GetResponseStream()) { using (var reader = new StreamReader(stream, true)) { while (!reader.EndOfStream) { list.Add(reader.ReadLine()); } } } } return list.ToArray(); } private FtpWebRequest createRequest(string uri, string method) { var r = (FtpWebRequest)WebRequest.Create(uri); r.Credentials = new NetworkCredential(TxtUsername.Text, TxtPassword.Text); r.Method = method; return r; }
Terrii
source share