Share via


No such host is known C#

Question

Thursday, June 15, 2017 6:02 AM

Hi,

Actually to connect  FTP i m using GetHostEntry (main_ipEndPoint = new IPEndPoint(Dns.GetHostEntry(ProxyServer).AddressList[0], port);). But while migrating the project .net framework 3.5 to 4.5 most of the FTP connection was failed and reporting "No such host is known" error. Please suggest what is the best alternative way of GetHostEntry .

Thanks,

Nandakumar.A

All replies (2)

Friday, June 16, 2017 3:27 AM

Hi Nandakumar A,

Thank you for posting here.

For your question, if you want to connect to the FTP, you could use FtpWebRequest to create connection and use NetworkCredential to logon.

Here is a simple example to upload the file. It works well for me.

 static void Main(string[] args)
        {
            // Get the object used to communicate with the server.  
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://localhost/N"+@"/"+"test1.xml");//uploadUrl + @"/" + fileName
            request.Method = WebRequestMethods.Ftp.UploadFile;

            // This example assumes the FTP site uses anonymous logon.  
            request.Credentials = new NetworkCredential("UserName", "PassWord");

            // Copy the contents of the file to the request stream.  
            StreamReader sourceStream = new StreamReader(@"C:\Users\v-wezan\Desktop\N1.xml");
            byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
            sourceStream.Close();
            request.ContentLength = fileContents.Length;

            Stream requestStream = request.GetRequestStream();
            requestStream.Write(fileContents, 0, fileContents.Length);
            requestStream.Close();

            FtpWebResponse response = (FtpWebResponse)request.GetResponse();

            Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

            response.Close();
        }

Best Regards,

Wendy

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].


Saturday, June 17, 2017 12:09 AM

Is ProxyServer the name of the machine you are trying to contact, or is it literally the address of an intermediate proxy server?

Tim Roberts, Driver MVP Providenza & Boekelheide, Inc.