Connecting to FTP site via VB.NET

Posted on 2006-04-10
Last Modified: 2011-10-03
Using IIS I created an FTP site called FTPTest.  The site allows anonymous connections.  If I type 'ftp://localhost/ftptest' into IE, I can see the documents and there are no problems.  However, if I attempt to do the same in code I get the following message:

System.Net.Sockets.SocketException: The requested name is valid and was found in the database, but does not have the correct associated data being resolved for
at System.Net.Dns.GetHostName
at  System.Net.Dns.Resolve, etc....

I have added the following line to my Hosts file:    FTPTest  (with the correct IP address of course)

I get this message on this line of code

         BuildConnection(Dns.Resolve(ServerAddr).AddressList(0), FtpPort) <----------------  Here
Catch err As Exception
End Try

Any help would be appreciated
Question by:JRossi1
    LVL 14

    Expert Comment

    If the value of the ServerAddr string is anything other than "FTPTest", try setting it to this value.


      Nayer Naguib
    LVL 14

    Accepted Solution

    Setting ServerAddr to "ftp://somehostname" or "http://somehostname" will also throw an exception.

    Otherwise, if you would like to set ServerAddr to "localhost/FTPTest", then you should modify the hostname in the hosts file to become "localhost/FTPTest".

    Note that when testing your code using other FTP hostname values, you should not use the "ftp://" prefix. This prefix specifies the *protocol*, which has nothing to do with the hostname. However, if the hostname includes the prefix "ftp." (as in ""), you *must* include it, as it is a part of the hostname.


      Nayer Naguib
    LVL 6

    Author Comment

    Sorry for not answering sooner.  I have been out sick.  Anyway, your advice regarding the Hosts file worked.  However, the FTP site is rejecting my password.  I have the 'Allow Anonymous Access' checked and I typed in my email address as the password, but it is not accepted.  Is there some default password that is used when the 'Allow Anonymous Access' is checked?


    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now