Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

GUI FTP Client Windows Form Catch Web exception Issue. Need help.

$
0
0

Hi there,

I have managed to get it to return an error for "NotLoggedIn" but it will then proceed to crash anyway.

I also have it working (as in it logs in and displays the folders) when the correct details are entered.

public string[] ListDirectory()
         {
             var list = listView1;
             var request = createRequest("ftp://" + host.Text.ToString() + "/", WebRequestMethods.Ftp.ListDirectory);
             try
             {
                 FtpWebResponse response = (FtpWebResponse)request.GetResponse();
             }
             catch (WebException ex)
             {
                 FtpWebResponse response = (FtpWebResponse)ex.Response;
                 if (response.StatusCode == FtpStatusCode.NotLoggedIn)
                 {
                     MessageBox.Show(response.StatusDescription);
                 }
             }
             using (var response = (FtpWebResponse)request.GetResponse())
             {
                 using (var stream = response.GetResponseStream())
                 {
                     using (var reader = new StreamReader(stream, true))
                     {
                         while (!reader.EndOfStream)
                         {
                             list.Items.Add(reader.ReadLine());
                         }
                     }
                 }
             } List<string> l = new List<string>();
             return l.ToArray();
         }

I need it to display a webexception error, without crashing afterwards.

I tried moving....

 using (var response = (FtpWebResponse)request.GetResponse())
             {
                 using (var stream = response.GetResponseStream())
                 {
                     using (var reader = new StreamReader(stream, true))
                     {
                         while (!reader.EndOfStream)
                         {
                             list.Items.Add(reader.ReadLine());
                         }
                     }
                 }
             } List<string> l = new List<string>();
             return l.ToArray();

 as an ELSE statement in response to the catch IF statement.

But then it didn't work. Any advice please?



Viewing all articles
Browse latest Browse all 12583

Latest Images

Trending Articles



Latest Images