2014-02-24 53 views
0

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

  '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。

+0

连接到服务器oter您能给我们这里一些更多的信息?什么是'sFileSource'的实际值,是网络共享上的文件等... – JaredPar

+0

sFileSource是\\ 192.168.1.25 \ TemFile \ file01.txt,该目录是共享的并具有完全权限 –

回答

0

我找到了答案,使用的系统DLL alow通过的NetBios

<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