简体   繁体   English

使用凭证的网络IO

[英]Network IO using Credentials

Is it possible to move files from a network location that requires credentials to another network location that also requires credentials without mapping any drive. 是否可以将文件从需要凭据的网络位置移动到也需要凭据的另一个网络位置,而无需映射任何驱动器。 (ie: Without any use of P/Invoke) (即:不使用P / Invoke)

Example: 例:

FileInfo fi = new FileInfo(@"\\SomeComputer\SomeDrive\SomeFolder\someFile.txt");
fi.MoveTo(@"\\AnotherComputer\AnotherDrive\AnotherFolder\AnotherFile.txt");

This works fine if the source and destination network drives are already mapped but if they are not It doesn't. 如果源网络驱动器和目标网络驱动器已映射,但未映射,则效果很好。

Try something like: 尝试类似:

    [DllImport("advapi32.dll")]
    private static extern int LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);

    /// <summary>
    /// Used for logging on the domain
    /// </summary>
    public enum LogonProvider
    {
        /// <summary>
        /// 
        /// </summary>
        LOGON32_PROVIDER_DEFAULT = 0,
        /// <summary>
        /// 
        /// </summary>
        LOGON32_PROVIDER_WINNT35 = 1,
        /// <summary>
        /// 
        /// </summary>
        LOGON32_PROVIDER_WINNT40 = 2,
        /// <summary>
        /// 
        /// </summary>
        LOGON32_PROVIDER_WINNT50 = 3
    };

    /// <summary>
    /// Used for logging on across the domain
    /// </summary>
    public enum LogonType
    {
        /// <summary>
        /// 
        /// </summary>
        LOGON32_LOGON_INTERACTIVE = 2,
        /// <summary>
        /// 
        /// </summary>
        LOGON32_LOGON_NETWORK = 3,
        /// <summary>
        /// 
        /// </summary>
        LOGON32_LOGON_BATCH = 4,
        /// <summary>
        /// 
        /// </summary>
        LOGON32_LOGON_SERVICE = 5,
        /// <summary>
        /// 
        /// </summary>
        LOGON32_LOGON_UNLOCK = 6,
        /// <summary>
        /// 
        /// </summary>
        LOGON32_LOGON_NETWORK_CLEARTEXT = 8,
        /// <summary>
        /// 
        /// </summary>
        LOGON32_LOGON_NEW_CREDENTIALS = 9
    }
 IntPtr token = new IntPtr();
 LogonUser(<username>, <domain>, <password>, (int)LogonType.LOGON32_LOGON_NEW_CREDENTIALS, (int)LogonProvider.LOGON32_PROVIDER_WINNT50, ref token);
 WindowsIdentity w = new WindowsIdentity(token);
 w.Impersonate();

This impersonates a domain user, and can then be used to copy files. 这将模拟域用户,然后可用于复制文件。

No. You'd need to p/invoke something . 不。您需要p /调用某些东西 This functionality is not provided in the BCL. BCL中未提供此功能。

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

相关问题 使用具有网络凭据的WebClient的uploaddata / uploadfile上的UnauthorizedAccessException - UnauthorizedAccessException on uploaddata/uploadfile using webclient with network credentials 使用网络凭证发送电子邮件 - Send email with out using network credentials 如何使用窗口服务中的凭据从其他网络访问文件 - How to access files from other network using credentials in window service 使用通用处理程序(ashx)中的网络凭据进行读取和身份验证 - Read and authentication using network credentials in a generic handler (ashx) 服务器应用程序,它获取用户凭据并使用这些凭据访问网络服务 - Server application that obtains user credentials and access network services using those credentials 网络凭据未保存在CredentialCache中 - Network Credentials not saving in CredentialCache Web应用程序,提示网络外的凭据并在网络上使用Windows凭据 - Web application that prompts credentials off network and uses Windows credentials on the network 可观察的网络IO解析 - Observable Network IO Parsing HttpClient.GetAsync 与网络凭据 - HttpClient.GetAsync with network credentials 为简单WebRequest设置网络凭据 - Setting Network Credentials for Simple WebRequest
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM