【问题标题】:Use Windows Credentials for FTP connection in .NET在 .NET 中使用 Windows 凭据进行 FTP 连接
【发布时间】:2011-07-06 13:20:32
【问题描述】:

一个与FTP Login using Windows Credentials 相关的问题,但在此线程上,讨论转向了另一个方向。

CredentialCache.DefaultCredentials 不适用于 FTP。有没有办法在 C# 中使用 Windows 用户帐户作为 FTP 连接的凭据?

如果 FTP 服务器可以接受 Kerberos 票证进行身份验证,您如何使用 FtpWebRequest 类发送它?

【问题讨论】:

    标签: c# .net ftp kerberos


    【解决方案1】:

    我不确定你在说什么凭据。

    如果你说的是 FTP 的用户名和密码,那么:

    R.Credentials = new NetworkCredential(UserName, Password);
    

    应该做的伎俩。

    如果您询问的是 Windows 使用的代理凭据来通过代理,就像 Explorer 或 Firefox 通过代理一样,那么:

    R.Proxy = new WebProxy();
    

    会成功的。

    【讨论】:

    • 我想使用当前登录的用户凭据
    【解决方案2】:

    以下是登录 FTP 的 3 种方法,但仍需要用户输入用户名或密码:

        System.Net.FtpWebRequest f = System.Net.FtpWebRequest.Create(new Uri("ftp://somewhere.com")) as System.Net.FtpWebRequest;
        if (f != null)
        {
            f.Credentials = new System.Net.NetworkCredential("username", "password", "domain");
            f.Credentials = new System.Net.NetworkCredential("username", "password");
            f.Credentials = new System.Net.NetworkCredential(System.Security.Principal.WindowsIdentity.GetCurrent().Name, "password");
        }
    

    最后一个取windows用户名,但仍需要某种方式从用户那里获取密码。

    【讨论】:

    • 我希望有一种方法可以将当前登录用户的 Kerberos 票证传递给 FTP 登录
    • 除了低级之外,我看不出如何使用当前可用的类来完成。即使我们使用一些第三方或开源库,它们仍然必须是低级的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-02
    • 1970-01-01
    • 2015-01-19
    • 1970-01-01
    • 2014-11-04
    • 1970-01-01
    • 2019-05-31
    相关资源
    最近更新 更多