Question : Trouble programmatically getting a list of the files on FTP server in VB.NET

I am using the attached code in an attempt to generate a list of the files located in a particular directory on an FTP server.  However, when testing the code in debug mode, the code generates the following exception:

System.Net.WebException was unhandled
  Message="The remote server returned an error: (550) File unavailable (e.g., file not found, no access)."

 

Some additional information that perhaps may be helpful: To manually doublecheck that my login credentials were working properly within VB, I CTRL + clicked on the link for the FTP directory within the VB project code.  I received a pop-up window that displays the same (550) error.  However, when I CTRL + click a second time, I successfully gain access to the directory.  This consistently only occurs on the second attempt, after receiving the 550 error on the first attempt.


Any help would be greatly appreciated.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
Public Sub GetList()
        Dim strList As New List(Of String)
        Dim fwr As FtpWebRequest = DirectCast(FtpWebRequest.Create(New Uri("ftp://servername.com/directoryname/directoryname/")), FtpWebRequest)
        fwr.Credentials = New NetworkCredential("xxxxxx", "xxxxxx")
        fwr.Method = WebRequestMethods.Ftp.ListDirectory
        Dim sr As New StreamReader(fwr.GetResponse().GetResponseStream())
        Dim str As String = sr.ReadLine()
        While str IsNot Nothing
            strList.Add(str)
            str = sr.ReadLine()
        End While
        sr.Close()
        sr = Nothing
        fwr = Nothing
    End Sub

Answer : Trouble programmatically getting a list of the files on FTP server in VB.NET

I ran your code, and it works fine on my side (after I changed my password to the correct one, and made sure the directory I was trying to read actually existed).

I only got the 550 when the directory was specified incorrectly. Can you confirm that is exists? (I couldn't get the Ctrl+Click to open the directory, regardless of how many times I clicked on it. I kept getting the same message)

Also, try using ftp://ftp.serv..... instead of just ftp://serv....
Random Solutions  
 
programming4us programming4us