【问题标题】:Copy a file of a server to another server from aspx从 aspx 将服务器的文件复制到另一台服务器
【发布时间】:2014-02-24 17:12:51
【问题描述】:

例如,我需要使用 asp.net/VB.NET 将文件从服务器复制到另一台服务器:

            'We copy the original file to the Temp dir
            If File.Exists(sFileSource) Then

                File.Copy(sFileSource, sFileDest, True)

            Else

                'The file doesn't exist

            End If

但是当验证文件是否存在得到文件不存在时,我看到另一个论坛是网络凭据问题,因为路径是 //192.168.1.10/TemFile/file01.txt。

【问题讨论】:

  • 你能在这里给我们更多的信息吗? sFileSource 的实际值是多少,是网络共享上的文件,等等...
  • sFileSource是\\192.168.1.25\TemFile\file01.txt,目录是共享的,有完全权限

标签: c# asp.net vb.net windows windows-server-2008


【解决方案1】:

我有答案,通过 NetBios 使用系统 dll 连接到其他服务器

<DllImport("advapi32.DLL", SetLastError:=True)> _
   Public Shared Function LogonUser(ByVal lpszUsername As String, ByVal lpszDomain As String, _
       ByVal lpszPassword As String, ByVal dwLogonType As Integer, ByVal dwLogonProvider As Integer, _
       ByRef phToken As IntPtr) As Integer
    End Function

Private _adminToken As IntPtr
Private _widCurrent As WindowsIdentity
Private _widAdmin As WindowsIdentity
Private _wic As WindowsImpersonationContext
Private _admin As AdminShared.AdminManager

If LogonUser(sUser, sDomain, sPassword, 9, 0, _adminToken) <> 0 Then

    _widAdmin = New WindowsIdentity(_adminToken)
    _wic = _widAdmin.Impersonate()

     File.Copy(sFileSource, sFileDest)

 Else

【讨论】:

    猜你喜欢
    • 2016-02-26
    • 2021-06-22
    • 2014-05-17
    • 2020-06-18
    • 1970-01-01
    • 2018-07-08
    • 2011-02-06
    • 2018-08-16
    • 1970-01-01
    相关资源
    最近更新 更多