Hi,
I've been working on my own class based around the FTPWebRequest class in .Net 2.0. I managed to get the class to the stage where it will list directory contents and download files and folders of my local ftp site. This however doesn't require any credentials. When i attempt to use it on the site i am going to be interested in downloading from i get an error coming back like so:
A first chance exception of type 'System.Net.WebException' occurred in System.dll
The remote server returned an error: (530) Not logged in.
I use the following code when trying to get the list from the site:
the ftp url, username and password are all getting passed in correctly, i'm really not sure as to why it isn't working. If anyone can help i'd really appreciate it.Code:public ArrayList listFilesAndFolders() { StreamReader reader = null; ArrayList alFilesAndFolders = new ArrayList(); if (m_address.Scheme != Uri.UriSchemeFtp) { return null; } try { FtpWebRequest listRequest = (FtpWebRequest)WebRequest.Create(getFTPPath(m_address.ToString())); listRequest.Timeout = 600000; listRequest.Method = WebRequestMethods.Ftp.ListDirectory; listRequest.Credentials = new NetworkCredential(m_username, m_password); FtpWebResponse listResponse = (FtpWebResponse)listRequest.GetResponse(); reader = new StreamReader(listResponse.GetResponseStream()); while (!reader.EndOfStream) { alFilesAndFolders.Add(reader.ReadLine().ToString().Trim()); } } catch (UriFormatException ex) { Debug.Print(ex.Message); return null; } catch (WebException ex) { Debug.Print(ex.Message); return null; } finally { if (reader != null) reader.Close(); } return alFilesAndFolders; }
(The ftp site is accessible via IE)
Cheers,
Grant




Reply With Quote