Results 1 to 2 of 2

Thread: [RESOLVED] FTP Credentials don't seem to be working [2.0]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Location
    Bonny Scotland
    Posts
    141

    Resolved [RESOLVED] FTP Credentials don't seem to be working [2.0]

    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:

    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 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.

    (The ftp site is accessible via IE)

    Cheers,

    Grant

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Location
    Bonny Scotland
    Posts
    141

    Re: FTP Credentials don't seem to be working [2.0]

    Apologies people,

    My fault. I was typing in the incorrect ftp URL

    Sorry.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width