2011年12月26日 星期一

VB.net FTP

   Public Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" _
(ByRef lpNetResource As NETRESOURCE, ByVal lpPassword As String, _
ByVal lpUserName As String, ByVal dwFlags As Integer) As Integer
    Public Declare Function WNetCancelConnection2 Lib "mpr" Alias "WNetCancelConnection2A" _
  (ByVal lpName As String, ByVal dwFlags As Integer, ByVal fForce As Integer) As Integer
    <StructLayout(LayoutKind.Sequential)> _

Public Structure NETRESOURCE
        Public dwScope As Integer
        Public dwType As Integer
        Public dwDisplayType As Integer
        Public dwUsage As Integer
        Public lpLocalName As String
        Public lpRemoteName As String
        Public lpComment As String
        Public lpProvider As String
    End Structure


    Public Const ForceDisconnect As Integer = 1
    Public Const RESOURCETYPE_DISK As Long = &H1
    Private Sub FTPOPEN()
        Dim nr = New NETRESOURCE
        nr.lpRemoteName = "路徑名稱"
        nr.lpLocalName = "x:"
        nr.dwType = RESOURCETYPE_DISK
        Dim result As Integer
        result = WNetAddConnection2(nr, "密碼", "帳號", 0)
    End Sub

標籤: