Copying file from Remote server to local and vice versa

前端 未结 2 510
梦如初夏
梦如初夏 2021-01-16 19:33

thanks for ur quick response. but im stucked with login only. im using following code to try to login:

bool success = LogonUser(\"username\", \"000.000.000.         


        
相关标签:
2条回答
  • 2021-01-16 19:54

    you need impersonation :

     [DllImport("advapi32.dll", SetLastError = true)]
        public static extern bool LogonUser(
                string lpszUsername,
                string lpszDomain,
                string lpszPassword,
                int dwLogonType,
                int dwLogonProvider,
                out IntPtr phToken);
    
    IntPtr userToken = IntPtr.Zero;
    
    bool success = External.LogonUser(
      "john.doe", 
      "domain.com", 
      "MyPassword", 
      (int) AdvApi32Utility.LogonType.LOGON32_LOGON_INTERACTIVE, //2
      (int) AdvApi32Utility.LogonProvider.LOGON32_PROVIDER_DEFAULT, //0
      out userToken);
    
    if (!success)
    {
      throw new SecurityException("Logon user failed");
    }
    
    using (WindowsIdentity.Impersonate(userToken))
    {
      // do the stuff with john.doe's credentials
    }
    
    0 讨论(0)
  • 2021-01-16 20:04

    We have a similar scenario in our project. We have created a user on the domain which has required permission on local and remote server (both servers in same domain). We have a windows service as well as web application both configured to run under this user context. Hence we don't get permission issues when coping the file to and from remote server.

    However if the remote server is not on the same domain, then you either user Impersonation(if possible) or configure a ftp server on remote machine. You can then upload and download files using ftp protocol.

    0 讨论(0)
提交回复
热议问题