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.
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
str = sr.ReadLine()
sr = Nothing
fwr = Nothing