Question

I need copy a file from server to another server using asp.net/VB.NET for example:

            '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

But when validate if file exists get that the file doesn't exist, I saw another forum that is a problem of network credentials because the paths are way //192.168.1.10/TemFile/file01.txt.

Was it helpful?

Solution

I have the answer, using a system dll alow connect to oter servers by 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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top