我需要使用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。
答案 0 :(得分:0)
我有答案,使用系统dll允许通过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