FTP目录选择

问题描述:

你好

我想为我打开最后一个线程后不久打开另一个线程而道歉.我搜索了过去两天的互联网,找不到解决方法.

May I first apologize for opening another thread so soon after my last one. I've searched the internet for the last two days and cannot find a solution.

我目前有一个功能,可以将图像上传到文本框内列出的ftp目录-我想对其进行升级,以便获取存储在ftp服务器中的文件夹列表并保存它们显示在组合内 盒子或类似的东西.

I currently have a feature which allows me to upload an image to an ftp directory which is listed inside a textbox - I would like to upgrade this so I could get the list of folders which are stored in the ftp server and have them displayed inside a combo box or something similar.

然后,我希望能够通过单击组合框中列出的相关目录名称来简单地选择要上传到的目录.这样,它将更改我的ftp URL路径,并且所选的图像将上传到所选的目录.

I would then like to be able to simply choose which directory I want to upload to by clicking on the relevant directory name listed in the combo box. By doing this it will change my ftp URL path and the chosen image will upload to the selected directory.

使用Visual Studio在Windows窗体内部是否可能?

Is this possible inside windows forms using visual studio?

下面是我当前的代码:

private void ConnectAndUpload()
        {
            try
            {
                string username = label61.Text;
                string password = label62.Text;
                string URLPath = maskedTextBox1.Text;
                string FilePath = textBox_image_path.Text;




                using (System.Net.WebClient client = new System.Net.WebClient())
                {
                    client.Credentials = new System.Net.NetworkCredential(username, password);
                    client.UploadFile(URLPath + "/" + new FileInfo(FilePath).Name, "STOR", FilePath);
                    MessageBox.Show("Image uploaded successfully");
                }

            }

            catch (Exception)
            {
                MessageBox.Show("FTP Upload failed, please check all your details are correct",
                    "FTP Upload Failed",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }


        }

再次,非常感谢您的帮助

Again, thanks so much for any help

为此功能,我使用了类FtpWebRequest和FtpWebResponse(http://msdn.microsoft.com/en-us/library/ms229718(v=vs .100).aspx )

您可以在此处找到示例:

You can find an example here:

http://msdn.microsoft.com/en-us/library/ms229716.aspx