wininet.dll, lastdllerror=6, what does it mean?

Discussion in 'ASP .Net' started by Sjaakie Helderhorst, Feb 5, 2004.

  1. Hi all,
    I'm trying to create a class which handles FTP. Knowing little of classes
    I'm having some trouble making things work. Also having trouble finding the
    meaning of some error-codes. The code below results in a lastdllerror 6 (and
    no transfer)... can't find what this error means and how to solve it (yes I
    already tried google). Could someone please help me out?

    This code should, on button-click, connect to ftp-server (192.168.20.1), get
    a file 'test.txt' from its root and store this file into 'c:\temp\test.txt'.
    Result-string to 'label1'.
    I created a class 'Ftp' to achieve this, without any luck sofar...

    Thanks in advance!

    ### [ Class ]
    Public Class Ftp

    Private Declare Function InternetCloseHandle Lib "wininet" (ByRef hInet
    As Long) As Long
    Private Declare Function InternetConnect Lib "wininet.dll" Alias
    "InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As
    String, ByVal nServerPort As Integer, ByVal sUserName As String, ByVal
    sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal
    lContext As Long) As Long
    Private Declare Function InternetOpen Lib "wininet.dll" Alias
    "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal
    sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As
    Long
    Private Declare Function FtpGetFile Lib "wininet.dll" Alias
    "FtpGetFileA" (ByVal hConnect As Long, ByVal lpszRemoteFile As String, ByVal
    lpszNewFile As String, ByVal fFailIfExists As Long, ByVal
    dwFlagsAndAttributes As Long, ByVal dwFlags As Long, ByRef dwContext As
    Long) As Boolean
    Private Declare Function FtpPutFile Lib "wininet.dll" Alias
    "FtpPutFileA" (ByVal hConnect As Long, ByVal lpszLocalFile As String, ByVal
    lpszNewRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long)
    As Boolean
    Private Declare Function InternetGetLastResponseInfo Lib "wininet.dll"
    Alias "InternetGetLastResponseInfoA" (ByVal lpdwError As Long, ByVal
    lpszBuffer As String, ByVal lpdwBufferLength As Long) As Boolean

    Dim strServer, strLogin, strPassword As String
    Dim INet, INetConn As Long

    Property Server() As String
    Get
    Return strServer
    End Get
    Set(ByVal Value As String)
    strServer = Value
    End Set
    End Property

    Property Login() As String
    Get
    Return strLogin
    End Get
    Set(ByVal Value As String)
    strLogin = Value
    End Set
    End Property

    Property Password() As String
    Get
    Return strPassword
    End Get
    Set(ByVal Value As String)
    strPassword = Value
    End Set
    End Property

    Public Function showError()
    Dim lErr As Long, sErr As String, lenBuf As Long
    InternetGetLastResponseInfo(lErr, sErr, lenBuf)
    sErr = lenBuf.ToString
    InternetGetLastResponseInfo(lErr, sErr, lenBuf)
    Return ("Error " + CStr(lErr) + ": " + sErr)
    End Function

    Public Sub openConnection()
    INet = InternetOpen("AceGroup FTP", 0, vbNullString, vbNullString,
    0)
    INetConn = InternetConnect(INet, Server, 21, Login, Password, 1, 0,
    0)
    End Sub

    Public Sub closeConnection()
    InternetCloseHandle(INetConn)
    InternetCloseHandle(INet)
    INet = 0
    INetConn = 0
    End Sub

    Public Function putFile(ByVal localFile As String, ByVal remoteFile As
    String) As String
    Dim result As String
    Try
    If INet = 0 Then openConnection()
    result = FtpPutFile(INetConn, localFile, remoteFile, 0,
    0).ToString
    Catch ex As Exception
    result = ex.ToString()
    Finally
    closeConnection()
    End Try

    Return result
    End Function

    Public Function getFile(ByVal remoteFile As String, ByVal localFile As
    String) As String
    Dim result As String
    Try
    If INet = 0 Then openConnection()
    result = FtpGetFile(INetConn, remoteFile, localFile, 0, 0, 1,
    0).ToString()
    Catch ex As Exception
    result = ex.ToString()
    Finally
    closeConnection()
    End Try

    Return result
    End Function

    End Class


    ### [Webform]
    [ ... ]
    Dim cFtp As Ftp = New Ftp
    Dim Result As String

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles Button1.Click

    cFtp.Server = "192.168.20.1"
    cFtp.Login = "[ my login ]"
    cFtp.Password = "[ my pass ]"

    cFtp.openConnection()
    Result = cFtp.getFile("test.txt", "c:\temp\test.txt")
    cFtp.closeConnection()
    ' output result to label
    label1.text = Result
    End Sub
     
    Sjaakie Helderhorst, Feb 5, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TmVpbA==?=

    How to Use WinInet for FTP in vb.net

    =?Utf-8?B?TmVpbA==?=, Sep 21, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,304
    =?Utf-8?B?TmVpbA==?=
    Sep 21, 2004
  2. Jonathan Allen

    Re: How to Use WinInet for FTP in vb.net

    Jonathan Allen, Sep 25, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,097
    AlexL [Xceed]
    Sep 28, 2004
  3. Jack Gibson

    wininet and ASP.NET server controls

    Jack Gibson, Sep 11, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    403
    Jack Gibson
    Sep 11, 2005
  4. Rick DeBay
    Replies:
    1
    Views:
    540
    Harald Hein
    Jul 6, 2003
  5. R M

    wininet.dll

    R M, Aug 12, 2004, in forum: ASP General
    Replies:
    1
    Views:
    137
    EricTsai - ???
    Aug 12, 2004
Loading...

Share This Page