Results 1 to 18 of 18

Thread: "wininet.dll" PLEASE HELP

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Location
    South Africa
    Posts
    8

    Unhappy "wininet.dll" PLEASE HELP

    I am trying to use the "wininet.dll" set of API's to download a single file of an FTP server. Listed below is the final procedure. I have not listed the constands or the API declerations.

    If I use this code with my ISP from home it works perfectly, but if I use it at work on our LAN through a proxy server it will not work.

    If I use FTP.exe to download the file at work it works perfectly.

    WHY WONT THIS WORK ON THE LAN. I have been up and down the NET on countless forums and help pages with tons of tutorials.

    PLEASE SOMEONE HELP!!!

    Sub Download()

    *****Gets the OPEN handle fine
    hOpen = InternetOpen("My Live Update program", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)

    If hOpen = 0 Then GoTo cls

    ****Gets the connection handle fine
    hConnection = InternetConnect(hOpen, "ftp.hp.com", INTERNET_DEFAULT_FTP_PORT, "username", "password", INTERNET_SERVICE_FTP, IIf(PassiveConnection, INTERNET_FLAG_PASSIVE, 0), 0)

    If hConnection = 0 Then GoTo cls

    ***THIS IS Where it goes wrong. chd returns false
    chd = FtpSetCurrentDirectory(hConnection, "pub/visualize/")
    dld = FtpGetFile(hConnection, "TopToolsRMDB.txt", "c:\TopToolsRMDB.txt", False, 0, FTP_TRANSFER_TYPE_UNKNOWN, 0)

    cls:
    On Error Resume Next
    InternetCloseHandle hConnection
    'close the internet connection
    InternetCloseHandle hOpen
    Exit Sub
    End Sub

  2. #2
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    There are some other ways --

    have alook at this page and the three links to other sample code pages

    http://www.mvps.org/vbnet/code/internet/ftpdownload.htm

  3. #3
    Addicted Member MathImagics's Avatar
    Join Date
    Jun 2002
    Location
    Uki, NSW Australia
    Posts
    169
    If your code is reproduced accurately, maybe your path is wrong.

    You've got "pub/visualize/" - the trailing "/" is ignored but that's no problem. But without a leading "/" you are asking for the directory relative to the current directory. Are you sure you know what that is?

    If your current directory is "/" and "/pub/visualize" exists then that's ok, but otherwise, you got a problem.

    Display the current directory (FtpGetCurrentDirectory) after the failed call and see if this gives a clue!

    Dr Memory
    "He's got a B.A. (in be-bop), a Ph.D. (in swing), he's a Master of Rhythm, he's the Rock'n'Roll king" ("The Rock'n'Roll Doctor", Lowell George)

    "If you push something hard enough, it will fall over" (Fudd's Third Law of Opposition)

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Location
    South Africa
    Posts
    8
    Hi,

    jim mcnamara

    I have tried that and it works but for the fact that for the site that I am connecting to I need a username and password.

    MathImagics

    It works perfectly if I dial in through an ISP, but will not work if I connect through the LAN through Proxy Server. Yet, if I use FTP.exe on the LAN I can download the file.

    Thanks for your replies, Please try and think of something else. I am going nuts trying to figure out the problem.

  5. #5
    Addicted Member MathImagics's Avatar
    Join Date
    Jun 2002
    Location
    Uki, NSW Australia
    Posts
    169
    Have you investigated the error code you get at the point where the API call fails - from what I remember of this API you should be able to get a clue from that .... sorry, I know 3/5 of 5/8 of diddly-squat about LAN's .....
    "He's got a B.A. (in be-bop), a Ph.D. (in swing), he's a Master of Rhythm, he's the Rock'n'Roll king" ("The Rock'n'Roll Doctor", Lowell George)

    "If you push something hard enough, it will fall over" (Fudd's Third Law of Opposition)

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Location
    South Africa
    Posts
    8
    That is the irritating thing. It does not generate an error. If it works the Boolean value is true if not it is false. I am going to try and remove the Boolean equals function and see if it returns an error.

    Thanks.

  7. #7

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Location
    South Africa
    Posts
    8
    Nothing happens, no error messages...Nothing

  8. #8
    Addicted Member MathImagics's Avatar
    Join Date
    Jun 2002
    Location
    Uki, NSW Australia
    Posts
    169
    The Forum's been down a couple of days ... seems to be a semi-regular occurrence ...

    Sorry if you already know this, but just in case you don't...

    If the FtpSetCurrentDirectory call returns 0, have a look at Err.LastDllError - it should have an error code ...
    "He's got a B.A. (in be-bop), a Ph.D. (in swing), he's a Master of Rhythm, he's the Rock'n'Roll king" ("The Rock'n'Roll Doctor", Lowell George)

    "If you push something hard enough, it will fall over" (Fudd's Third Law of Opposition)

  9. #9

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Location
    South Africa
    Posts
    8
    This is excellent. The error returned is 12003. If you do know what this error means please let me know. I am going to search for it now.

    Thanks

  10. #10
    Addicted Member MathImagics's Avatar
    Join Date
    Jun 2002
    Location
    Uki, NSW Australia
    Posts
    169
    OK, now we're getting somewhere...

    12003 is ERROR_INTERNET_EXTENDED_ERROR

    I have code for interpreting this error somewhere ... give me 30 mins (I'm at work!) and I'll try and find it ....


    Dr Memory:
    "He's got a B.A. (in be-bop), a Ph.D. (in swing), he's a Master of Rhythm, he's the Rock'n'Roll king" ("The Rock'n'Roll Doctor", Lowell George)

    "If you push something hard enough, it will fall over" (Fudd's Third Law of Opposition)

  11. #11
    Addicted Member MathImagics's Avatar
    Join Date
    Jun 2002
    Location
    Uki, NSW Australia
    Posts
    169
    Here's how you get a string interpretation of FTP errors:

    VB Code:
    1. Function ErrorOut(dError As Long) As String
    2.     Dim dwIntError As Long, dwLength As Long
    3.     Dim strBuffer As String
    4.     If dError = ERROR_INTERNET_EXTENDED_ERROR Then
    5.         InternetGetLastResponseInfo dwIntError, vbNullString, dwLength
    6.         strBuffer = String(dwLength + 1, 0)
    7.         InternetGetLastResponseInfo dwIntError, strBuffer, dwLength
    8.         ErrorOut = " FTP Err: " & dwIntError & " " & strBuffer
    9.    Else
    10.       ErrorOut = "Error " & dError & vbLF & InetErrMsg(dError)
    11.     End If
    12.   End Function
    "He's got a B.A. (in be-bop), a Ph.D. (in swing), he's a Master of Rhythm, he's the Rock'n'Roll king" ("The Rock'n'Roll Doctor", Lowell George)

    "If you push something hard enough, it will fall over" (Fudd's Third Law of Opposition)

  12. #12
    Addicted Member MathImagics's Avatar
    Join Date
    Jun 2002
    Location
    Uki, NSW Australia
    Posts
    169
    You'll need this as well (for codes other than 12003)

    VB Code:
    1. Function InetErrMsg$(ByVal ecode&)
    2.    Dim emsg$
    3.    If ecode = ERROR_IO_PENDING Then
    4.       InetErrMsg = "ERROR_IO_PENDING "
    5.       Exit Function
    6.       End If
    7.      
    8.    If ecode < 12000 Then
    9.       Err.Number = ecode
    10.       InetErrMsg = Err.Description
    11.       Exit Function
    12.       End If
    13.      
    14.    Select Case (ecode - 12000)
    15.       Case 0: emsg = "(NO FTP HANDLE)"
    16.       Case 1: emsg = "ERROR_INTERNET_OUT_OF_HANDLES"
    17.       Case 2: emsg = "ERROR_INTERNET_TIMEOUT"
    18.       Case 3: emsg = "ERROR_INTERNET_EXTENDED_ERROR"
    19.       Case 4: emsg = "ERROR_INTERNET_INTERNAL_ERROR"
    20.       Case 5: emsg = "ERROR_INTERNET_INVALID_URL"
    21.       Case 6: emsg = "ERROR_INTERNET_UNRECOGNIZED_SCHEME"
    22.       Case 7: emsg = "ERROR_INTERNET_NAME_NOT_RESOLVED"
    23.       Case 8: emsg = "ERROR_INTERNET_PROTOCOL_NOT_FOUND"
    24.       Case 9: emsg = "ERROR_INTERNET_INVALID_OPTION"
    25.       Case 10: emsg = "ERROR_INTERNET_BAD_OPTION_LENGTH"
    26.       Case 11: emsg = "ERROR_INTERNET_OPTION_NOT_SETTABLE"
    27.       Case 12: emsg = "ERROR_INTERNET_SHUTDOWN"
    28.       Case 13: emsg = "The Username provided is invalid" ' ERROR_INTERNET_INCORRECT_USER_NAME
    29.       Case 14: emsg = "Invalid Usercode or Password"     ' ERROR_INTERNET_INCORRECT_PASSWORD
    30.       Case 15: emsg = "ERROR_INTERNET_LOGIN_FAILURE"
    31.       Case 16: emsg = "ERROR_INTERNET_INVALID_OPERATION"
    32.       Case 17: emsg = "ERROR_INTERNET_OPERATION_CANCELLED"
    33.       Case 18: emsg = "ERROR_INTERNET_INCORRECT_HANDLE_TYPE"
    34.       Case 19: emsg = "ERROR_INTERNET_INCORRECT_HANDLE_STATE"
    35.       Case 20: emsg = "ERROR_INTERNET_NOT_PROXY_REQUEST"
    36.       Case 21: emsg = "ERROR_INTERNET_REGISTRY_VALUE_NOT_FOUND"
    37.       Case 22: emsg = "ERROR_INTERNET_BAD_REGISTRY_PARAMETER"
    38.       Case 23: emsg = "ERROR_INTERNET_NO_DIRECT_ACCESS"
    39.       Case 24: emsg = "ERROR_INTERNET_NO_CONTEXT"
    40.       Case 25: emsg = "ERROR_INTERNET_NO_CALLBACK"
    41.       Case 26: emsg = "ERROR_INTERNET_REQUEST_PENDING"
    42.       Case 27: emsg = "ERROR_INTERNET_INCORRECT_FORMAT"
    43.       Case 28: emsg = "ERROR_INTERNET_ITEM_NOT_FOUND"
    44.       Case 29: emsg = "ERROR_INTERNET_CANNOT_CONNECT"
    45.       Case 30: emsg = "ERROR_INTERNET_CONNECTION_ABORTED"
    46.       Case 31: emsg = "ERROR_INTERNET_CONNECTION_RESET"
    47.       Case 32: emsg = "ERROR_INTERNET_FORCE_RETRY"
    48.       Case 33: emsg = "ERROR_INTERNET_INVALID_PROXY_REQUEST"
    49.       Case 34: emsg = "ERROR_INTERNET_NEED_UI"
    50.       Case 36: emsg = "ERROR_INTERNET_HANDLE_EXISTS"
    51.  
    52.       Case 37: emsg = "ERROR_INTERNET_SEC_CERT_DATE_INVALID"
    53.       Case 38: emsg = "ERROR_INTERNET_SEC_CERT_CN_INVALID"
    54.       Case 39: emsg = "ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR"
    55.       Case 40: emsg = "ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR"
    56.       Case 41: emsg = "ERROR_INTERNET_MIXED_SECURITY"
    57.       Case 42: emsg = "ERROR_INTERNET_CHG_POST_IS_NON_SECURE"
    58.       Case 43: emsg = "ERROR_INTERNET_POST_IS_NON_SECURE"
    59.       Case 44: emsg = "ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED"
    60.       Case 45: emsg = "ERROR_INTERNET_INVALID_CA"
    61.       Case 46: emsg = "ERROR_INTERNET_CLIENT_AUTH_NOT_SETUP"
    62.       Case 47: emsg = "ERROR_INTERNET_ASYNC_THREAD_FAILED"
    63.       Case 48: emsg = "ERROR_INTERNET_REDIRECT_SCHEME_CHANGE"
    64.       Case 49: emsg = "ERROR_INTERNET_DIALOG_PENDING"
    65.       Case 50: emsg = "ERROR_INTERNET_RETRY_DIALOG"
    66.       Case 52: emsg = "ERROR_INTERNET_HTTPS_HTTP_SUBMIT_REDIR"
    67.       Case 53: emsg = "ERROR_INTERNET_INSERT_CDROM"
    68.  
    69.       Case 110: emsg = "ERROR_FTP_TRANSFER_IN_PROGRESS"
    70.       Case 111: emsg = "ERROR_FTP_DROPPED"
    71.       Case 112: emsg = "ERROR_FTP_NO_PASSIVE_MODE"
    72.  
    73. '
    74. ' gopher API errors
    75. '
    76.  
    77.       Case 130: emsg = "ERROR_GOPHER_PROTOCOL_ERROR"
    78.       Case 131: emsg = "ERROR_GOPHER_NOT_FILE"
    79.       Case 132: emsg = "ERROR_GOPHER_DATA_ERROR"
    80.       Case 133: emsg = "ERROR_GOPHER_END_OF_DATA"
    81.       Case 134: emsg = "ERROR_GOPHER_INVALID_LOCATOR"
    82.       Case 135: emsg = "ERROR_GOPHER_INCORRECT_LOCATOR_TYPE"
    83.       Case 136: emsg = "ERROR_GOPHER_NOT_GOPHER_PLUS"
    84.       Case 137: emsg = "ERROR_GOPHER_ATTRIBUTE_NOT_FOUND"
    85.       Case 138: emsg = "ERROR_GOPHER_UNKNOWN_LOCATOR"
    86.  
    87. '
    88. ' HTTP API errors
    89. '
    90.  
    91.       Case 150: emsg = "ERROR_HTTP_HEADER_NOT_FOUND"
    92.       Case 151: emsg = "ERROR_HTTP_DOWNLEVEL_SERVER"
    93.       Case 152: emsg = "ERROR_HTTP_INVALID_SERVER_RESPONSE"
    94.       Case 153: emsg = "ERROR_HTTP_INVALID_HEADER"
    95.       Case 154: emsg = "ERROR_HTTP_INVALID_QUERY_REQUEST"
    96.       Case 155: emsg = "ERROR_HTTP_HEADER_ALREADY_EXISTS"
    97.       Case 156: emsg = "ERROR_HTTP_REDIRECT_FAILED"
    98.       Case 160: emsg = "ERROR_HTTP_NOT_REDIRECTED"
    99.       Case 161: emsg = "ERROR_HTTP_COOKIE_NEEDS_CONFIRMATION"
    100.       Case 162: emsg = "ERROR_HTTP_COOKIE_DECLINED"
    101.       Case 168: emsg = "ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION"
    102.  
    103. '
    104. ' additional Internet API error codes
    105. '
    106.  
    107.       Case 157: emsg = "ERROR_INTERNET_SECURITY_CHANNEL_ERROR"
    108.       Case 158: emsg = "ERROR_INTERNET_UNABLE_TO_CACHE_FILE"
    109.       Case 159: emsg = "ERROR_INTERNET_TCPIP_NOT_INSTALLED"
    110.       Case 163: emsg = "ERROR_INTERNET_DISCONNECTED"
    111.       Case 164: emsg = "ERROR_INTERNET_SERVER_UNREACHABLE"
    112.       Case 165: emsg = "ERROR_INTERNET_PROXY_SERVER_UNREACHABLE"
    113.  
    114.       Case 166: emsg = "ERROR_INTERNET_BAD_AUTO_PROXY_SCRIPT"
    115.       Case 167: emsg = "ERROR_INTERNET_UNABLE_TO_DOWNLOAD_SCRIPT"
    116.       Case 169: emsg = "ERROR_INTERNET_SEC_INVALID_CERT"
    117.       Case 170: emsg = "ERROR_INTERNET_SEC_CERT_REVOKED"
    118.  
    119.       Case Else: emsg = "(not a recognised error code)"
    120.       End Select
    121.    InetErrMsg = emsg
    122. End Function
    "He's got a B.A. (in be-bop), a Ph.D. (in swing), he's a Master of Rhythm, he's the Rock'n'Roll king" ("The Rock'n'Roll Doctor", Lowell George)

    "If you push something hard enough, it will fall over" (Fudd's Third Law of Opposition)

  13. #13
    Addicted Member MathImagics's Avatar
    Join Date
    Jun 2002
    Location
    Uki, NSW Australia
    Posts
    169
    and the API declarations...

    VB Code:
    1. Public Const ERROR_IO_PENDING = 997
    2. Public Const ERROR_INTERNET_EXTENDED_ERROR = 12003
    3.  
    4. Public Declare Function InternetGetLastResponseInfo Lib "wininet.dll" Alias "InternetGetLastResponseInfoA" ( _
    5.     lpdwError As Long, _
    6.     ByVal lpszBuffer As String, _
    7.     lpdwBufferLength As Long) As Boolean


    I reckon now you've got more than enough to go on with!!!

    Let me know what happens ......


    Dr Memory
    Last edited by MathImagics; Aug 13th, 2002 at 09:54 AM.
    "He's got a B.A. (in be-bop), a Ph.D. (in swing), he's a Master of Rhythm, he's the Rock'n'Roll king" ("The Rock'n'Roll Doctor", Lowell George)

    "If you push something hard enough, it will fall over" (Fudd's Third Law of Opposition)

  14. #14

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Location
    South Africa
    Posts
    8
    This is the error string it is returning.

    " FTP Err: 0 500 must be connected to remote server
    "

    What is the procedure to go through a proxy server? Do you first have to establish a connection to the proxy and then a connection to the site, or is it all automatic, you just go to the site?

  15. #15
    Addicted Member MathImagics's Avatar
    Join Date
    Jun 2002
    Location
    Uki, NSW Australia
    Posts
    169
    Sorry, mate, once we start discussing proxy servers, we have gone beyond my area of expertise and/or interest ....

    However, look at MSDN - my local copy (dated 1998) found a dozen articles discussing FTP and proxy servers - apparently there are (or were) some limitations and/or behavioural peculiarities - suggest connect to MSDN web-site and search for "ftp AND proxy" - also search VB forums for same (found 13 on this site)

    Good luck......
    "He's got a B.A. (in be-bop), a Ph.D. (in swing), he's a Master of Rhythm, he's the Rock'n'Roll king" ("The Rock'n'Roll Doctor", Lowell George)

    "If you push something hard enough, it will fall over" (Fudd's Third Law of Opposition)

  16. #16

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Location
    South Africa
    Posts
    8
    Thanks for your help. I have learnt some more again and I appreciate your effort and interest. When I find the answer I will post it here and maybe someone else will be helped.

    Thanks...

  17. #17
    Addicted Member MathImagics's Avatar
    Join Date
    Jun 2002
    Location
    Uki, NSW Australia
    Posts
    169
    These snippets from MSDN might be of use ...

    Sample program going through a proxy server appears to be using INTERNET_OPEN_TYPE_PROXY flag, (not PRECONFIG) in the InternetOpen call.

    Some relevant (possibly) MSDN articles:
    Q170038, Q172712 , Q168492, Q166961
    "He's got a B.A. (in be-bop), a Ph.D. (in swing), he's a Master of Rhythm, he's the Rock'n'Roll king" ("The Rock'n'Roll Doctor", Lowell George)

    "If you push something hard enough, it will fall over" (Fudd's Third Law of Opposition)

  18. #18
    New Member
    Join Date
    May 2015
    Posts
    11

    Re: "wininet.dll" PLEASE HELP

    Hello,
    Forgive me for my bad english, I'm french.

    Can you give me an example of adapting your code on my own?

    Code:
    Const FTP_TRANSFER_TYPE_UNKNOWN = &H0
    Const FTP_TRANSFER_TYPE_ASCII = &H1
    Const FTP_TRANSFER_TYPE_BINARY = &H2
    Const INTERNET_DEFAULT_FTP_PORT = 21             
    Const INTERNET_SERVICE_FTP = 1
    Const INTERNET_FLAG_PASSIVE = &H8000000            
    Const INTERNET_OPEN_TYPE_PRECONFIG = 0                   
    Const MAX_PATH = 260
    
    Private Type WIN32_FIND_DATA
     cFileName As String * MAX_PATH
    
    End Type
    Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
    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 FtpGetCurrentDirectory Lib "wininet.dll" Alias "FtpGetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszCurrentDirectory As String, lpdwCurrentDirectory As Long) As Long
    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
    Const PassiveConnection As Boolean = True
    
    Private Sub cmd_exit_Click()
    End
    End Sub
    
    Private Sub cmd_send_Click()
        Dim hConnection As Long, hOpen As Long, sOrgPath  As String
        'open an internet connection
        hOpen = InternetOpen("API-Guide sample program", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
        'connect to the FTP server
        hConnection = InternetConnect(hOpen, txt_ftp.Text, INTERNET_DEFAULT_FTP_PORT, txt_login.Text, txt_pw.Text, INTERNET_SERVICE_FTP, IIf(PassiveConnection, INTERNET_FLAG_PASSIVE, 0), 0)
        'create a buffer to store the original directory
        sOrgPath = String(MAX_PATH, 0)
        'get the directory
        FtpGetCurrentDirectory hConnection, sOrgPath, Len(sOrgPath)
        'upload the file 'test.htm'
        FtpPutFile hConnection, "" & App.Path & "\Mon.txt", "", FTP_TRANSFER_TYPE_UNKNOWN, 0
        'close the internet connection
        InternetCloseHandle hOpen
        MsgBox ("Sucesful")
    End Sub
    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width