gpt4 book ai didi

c# - "Hostname could not be parsed"来自 "ftp"网址

转载 作者:行者123 更新时间:2023-11-30 14:58:36 25 4
gpt4 key购买 nike

我刚刚从 GoDaddy 购买了一些在线存储空间,并尝试通过 FTP 传输到我的存储帐户。问题是,我可以使用 FileZilla 查看和修改我的帐户,但由于“无法解析主机名”错误,我的 C Sharp 程序甚至无法访问它。

我认为这是因为我帐户的整个 ftp 地址在 url 中有两个“@”符号,这是 URI 创建过程中的严重破坏。

无论如何我都可以解决这个问题,还是因为 GoDaddy 存储的命名约定我搞砸了?

网址是:ftp:[slashslash]lastname.firstname@gmail.com@onlinefilefolder.com/Home/

最佳答案

是否出于某些特定原因需要在 URI 中指定用户名和密码?您可以简单地连接到主机,然后提供凭据。

// Create a request to the host
var request = (FtpWebRequest)WebRequest.Create("ftp://onlinefilefolder.com");

// Set the username and password to use
request.Credentials = new NetworkCredential ("lastname.firstname@gmail.com","password");

request.Method = WebRequestMethods.Ftp.UploadFile;

var sourceStream = new StreamReader("testfile.txt");
var 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# - "Hostname could not be parsed"来自 "ftp"网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18521004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com