简体   繁体   English

登录失败:用户名未知或密码错误。 使用C#的FTP

[英]Logon failure: unknown user name or bad password. FTP with C#

I am trying to access an FTP server that is outside our network to get a CSV file. 我正在尝试访问网络之外的FTP服务器以获取CSV文件。 Here is the code that I am using 这是我正在使用的代码

string XMLPATH = @"\\server\file.csv";
FileWebRequest request = (FileWebRequest)FileWebRequest.Create(XMLPATH);
request.Credentials = new NetworkCredential("admin", "password");
FileWebResponse response = request.GetResponse() as FileWebResponse;
Stream stReader = response.GetResponseStream();

When I run this through my console app, I get this message. 通过控制台应用程序运行此消息时,会收到此消息。

Logon failure: unknown user name or bad password

If I go to the server location to get the file in Windows Explorer, I am able to login just fine and retrieve the file. 如果我转到服务器位置以在Windows资源管理器中获取文件,则可以正常登录并检索文件。 After that, my application can access the file just fine. 之后,我的应用程序可以正常访问文件。 I read this previous stack thread 我阅读了之前的堆栈线程

Logon failure: unknown user name or bad password? 登录失败:用户名未知或密码错误? But I am using the right username and password 但是我使用正确的用户名和密码

And I added this to my config 我将此添加到我的配置中

<system.net>
 <defaultProxy useDefaultCredentials="false">
  <proxy usesystemdefault="True"/>
 </defaultProxy>
</system.net>

And that changes nothing. 那并没有改变。 I have also tried to add my domain to the Credentials Constructor, but that does not fix anything either. 我也尝试过将我的域添加到凭据构造器中,但这也不能解决任何问题。 This connection needs to be done as a client application, so the previous post is a little different than mine. 此连接需要作为客户端应用程序完成,因此上一篇文章与我的文章略有不同。 Any help would be greatly appreciated. 任何帮助将不胜感激。 Thanks 谢谢

EDIT 编辑

Because I was curious, I ran a Wireshark trace on the call for both the Windows Explorer and my application's request. 因为我很好奇,所以我在对Windows资源管理器和应用程序请求的调用中运行了Wireshark跟踪。 When using explorer, it send the request using the proper credentials. 使用资源管理器时,它将使用正确的凭据发送请求。 However when I use the application, it sends the request as the logged in name of my machine (aka my user id). 但是,当我使用该应用程序时,它会将请求作为计算机的登录名(即我的用户ID)发送。 Why is it when I send the request credentials in the request, it still defaults to the logged in user? 为什么当我在请求中发送请求凭据时,它仍默认为已登录用户? Is there a setting I have to configure for this? 是否需要为此设置一个设置?

我怀疑您需要指定一个域(或计算机名):

new NetworkCredential("admin", "password", domainOrComputerName)

I was able to fix this by creating a local user on the server that will run the application. 我能够通过在将运行该应用程序的服务器上创建本地用户来解决此问题。 This user would be setup the exact same way as user that has read rights to the FTP server 该用户的设置方式与对FTP服务器具有读取权限的用户完全相同

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 登录失败:用户名未知或密码错误 - Logon failure: unknown user name or bad password StreamWriter引发IOException登录失败:用户名未知或密码错误 - StreamWriter throws IOException Logon failure: unknown user name or bad password 登录失败:用户名未知或密码错误? 但是我使用正确的用户名和密码 - Logon failure: unknown user name or bad password? But I am using the right username and password 登录失败:用户名未知或密码错误。访问其他服务器时出错 - Logon failure: unknown user name or bad password.error while accessing other server 登录失败:在远程计算机中创建文件夹时,用户名未知或密码错误 - Logon failure: unknown user name or bad password while creating folder in remote machine Image.FromFile和用户名密码。 C# - Image.FromFile with a username password. C# UNC LogonUser:未知用户或密码错误 - UNC LogonUser: Unknown user or bad password C#共享文件夹访问使登录失败异常 - C# shared folder access gives Logon failure exception c#服务如何在Terminal Services Server上标识当前用户登录名? - How can c# service identify current user logon name on Terminal Services Server? C#代码无法更改AD密码。 (System.Runtime.InteropServices.COMException) - C# code cannot change AD password. (System.Runtime.InteropServices.COMException)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM