I have a piece of code that downloads a particular file from multiple target sites. A typical connection string looks like this:-
host = ftp://1.2.3.4/e:/CDR/*.tmp
and I run the following code to get the actual filename i want to download
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'Get the TMP filename
Dim dirrequest As FtpWebRequest = FtpWebRequest.Create(host)
dirrequest.Method = WebRequestMethods.Ftp.ListDirectory
dirrequest.UsePassive = False
dirrequest.Credentials = New NetworkCredential(username, password)
Dim dirresponse As WebResponse = dirrequest.GetResponse
Dim filenamereader As StreamReader = New StreamReader(dirresponse.GetResponseStream)
Dim filename As String = filenamereader.ReadToEnd
dirresponse.Close()
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
This code works perfectly for all the machines I need to contact. My problem comes from changing the connection string to specify a port number e.g.
host = ftp://1.2.3.4:8021/e:/CDR/*.tmp
When I run the code the request just throws a timeout exception on GetResponse()
I tried setting the request to .UsePassive =True and this just caused it to never return from the GetResponseStream.
I can contact the machine directly from explorer if I cut and paste the connection string in, so i know it isn't a connection problem on my PC.
This is really bugging me now -enough to actually post on a forum! I've been able to solve every problem up to now reading other peoples postings but this one has beaten me. According to all the documentation it should just work in this format. I must say, though, that although I've been developing for years I'm new to both vb.net and FTP so this could be an obvious problem that everyone (but me) knows the answer to - but I'm not proud, feel free to speak down to me :-)
What am I missing??????
Thanks in advance for any suggestions :-)
!--removed tag-->
Enter your message below
Sign in or Join us (it's free).