Hello,
I want to browse the folders available in an ftp account,
I managed to browse the files but only the files on the root,
I want to be able to browse the folders
I am trying to make a upload app where you can CHOOSE a folder from the ftp to upload the file there,
private void getFileList()
{
List<string> files = new List<string>();
try
{
this.Text = "Connecting...";
Application.DoEvents();
FtpWebRequest request = FtpWebRequest.Create(ftpAddress) as FtpWebRequest;
request.Method = WebRequestMethods.Ftp.ListDirectory;
request.Credentials = new NetworkCredential(ftpusername, ftppassword);
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false;
this.Text = "Retrieving List...";
Application.DoEvents();
FtpWebResponse response = request.GetResponse() as FtpWebResponse;
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
while (!reader.EndOfStream)
{
Application.DoEvents();
files.Add(reader.ReadLine());
}
reader.Close();
responseStream.Close();
response.Close();
}
catch (Exception)
{
MessageBox.Show("There was an error connecting to the FTP Server");
}
if (files.Count != 0)
{
listDialogForm dialog = new listDialogForm(files);
if (dialog.ShowDialog() == DialogResult.OK)
{
}
}
}
and this is for browsing:
public partial class listDialogForm : Form
{
private List<string> fileList = new List<string>();
private string chosenFile;
private bool p;
public listDialogForm(List<string> files)
{
InitializeComponent();
fileList = files;
}
public listDialogForm(bool p)
{
this.p = p;
}
public string ChosenFile
{
get { return chosenFile; }
}
private void listDialogForm_Load(object sender, EventArgs e)
{
btnOK.DialogResult = DialogResult.OK;
btnCancel.DialogResult = DialogResult.Cancel;
foreach (string file in fileList)
{
if(!file.ToString().Contains("."))
listBox1.Items.Add(file);
}
}
private void btnOK_Click(object sender, EventArgs e)
{
if (listBox1.SelectedIndex != -1)
chosenFile = listBox1.SelectedItem.ToString();
}
}
}
if the file contains any "dot" dont show it,
so I can see only the folders
if(!file.ToString().Contains("."))
listBox1.Items.Add(file);
but I want to enter them and save their destination,,,