没有这样的主机是已知的C# [英] No such host is known C#

查看:98
本文介绍了没有这样的主机是已知的C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上是为了连接使用 GetHostEntry (main_ipEndPoint =新IPEndPoint(Dns. GetHostEntry (ProxyServer).AddressList [0],端口);)进行FTP.但是,在将项目.net Framework 3.5迁移到4.5时,大部分FTP连接 失败,并报告未知此类主机". 错误.请提出 GetHostEntry的最佳替代方法是什么.

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 .

谢谢

Nandakumar.A

Nandakumar.A

推荐答案

Nandakumar A,

Hi Nandakumar A,

谢谢您在这里发布.

对于您的问题,如果要连接到FTP,可以使用 要登录的网络凭据.

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();
        }

最好的问候,

温迪


这篇关于没有这样的主机是已知的C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆