|
-
Aug 8th, 2002, 01:09 PM
#1
Thread Starter
New Member
"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
-
Aug 8th, 2002, 02:59 PM
#2
Frenzied Member
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
-
Aug 8th, 2002, 03:36 PM
#3
Addicted Member
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)
-
Aug 10th, 2002, 03:07 AM
#4
Thread Starter
New Member
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.
-
Aug 10th, 2002, 04:07 PM
#5
Addicted Member
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)
-
Aug 13th, 2002, 02:03 AM
#6
Thread Starter
New Member
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.
-
Aug 13th, 2002, 02:13 AM
#7
Thread Starter
New Member
Nothing happens, no error messages...Nothing
-
Aug 13th, 2002, 04:38 AM
#8
Addicted Member
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)
-
Aug 13th, 2002, 08:39 AM
#9
Thread Starter
New Member
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
-
Aug 13th, 2002, 09:02 AM
#10
Addicted Member
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)
-
Aug 13th, 2002, 09:20 AM
#11
Addicted Member
Here's how you get a string interpretation of FTP errors:
VB Code:
Function ErrorOut(dError As Long) As String
Dim dwIntError As Long, dwLength As Long
Dim strBuffer As String
If dError = ERROR_INTERNET_EXTENDED_ERROR Then
InternetGetLastResponseInfo dwIntError, vbNullString, dwLength
strBuffer = String(dwLength + 1, 0)
InternetGetLastResponseInfo dwIntError, strBuffer, dwLength
ErrorOut = " FTP Err: " & dwIntError & " " & strBuffer
Else
ErrorOut = "Error " & dError & vbLF & InetErrMsg(dError)
End If
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)
-
Aug 13th, 2002, 09:24 AM
#12
Addicted Member
You'll need this as well (for codes other than 12003)
VB Code:
Function InetErrMsg$(ByVal ecode&)
Dim emsg$
If ecode = ERROR_IO_PENDING Then
InetErrMsg = "ERROR_IO_PENDING "
Exit Function
End If
If ecode < 12000 Then
Err.Number = ecode
InetErrMsg = Err.Description
Exit Function
End If
Select Case (ecode - 12000)
Case 0: emsg = "(NO FTP HANDLE)"
Case 1: emsg = "ERROR_INTERNET_OUT_OF_HANDLES"
Case 2: emsg = "ERROR_INTERNET_TIMEOUT"
Case 3: emsg = "ERROR_INTERNET_EXTENDED_ERROR"
Case 4: emsg = "ERROR_INTERNET_INTERNAL_ERROR"
Case 5: emsg = "ERROR_INTERNET_INVALID_URL"
Case 6: emsg = "ERROR_INTERNET_UNRECOGNIZED_SCHEME"
Case 7: emsg = "ERROR_INTERNET_NAME_NOT_RESOLVED"
Case 8: emsg = "ERROR_INTERNET_PROTOCOL_NOT_FOUND"
Case 9: emsg = "ERROR_INTERNET_INVALID_OPTION"
Case 10: emsg = "ERROR_INTERNET_BAD_OPTION_LENGTH"
Case 11: emsg = "ERROR_INTERNET_OPTION_NOT_SETTABLE"
Case 12: emsg = "ERROR_INTERNET_SHUTDOWN"
Case 13: emsg = "The Username provided is invalid" ' ERROR_INTERNET_INCORRECT_USER_NAME
Case 14: emsg = "Invalid Usercode or Password" ' ERROR_INTERNET_INCORRECT_PASSWORD
Case 15: emsg = "ERROR_INTERNET_LOGIN_FAILURE"
Case 16: emsg = "ERROR_INTERNET_INVALID_OPERATION"
Case 17: emsg = "ERROR_INTERNET_OPERATION_CANCELLED"
Case 18: emsg = "ERROR_INTERNET_INCORRECT_HANDLE_TYPE"
Case 19: emsg = "ERROR_INTERNET_INCORRECT_HANDLE_STATE"
Case 20: emsg = "ERROR_INTERNET_NOT_PROXY_REQUEST"
Case 21: emsg = "ERROR_INTERNET_REGISTRY_VALUE_NOT_FOUND"
Case 22: emsg = "ERROR_INTERNET_BAD_REGISTRY_PARAMETER"
Case 23: emsg = "ERROR_INTERNET_NO_DIRECT_ACCESS"
Case 24: emsg = "ERROR_INTERNET_NO_CONTEXT"
Case 25: emsg = "ERROR_INTERNET_NO_CALLBACK"
Case 26: emsg = "ERROR_INTERNET_REQUEST_PENDING"
Case 27: emsg = "ERROR_INTERNET_INCORRECT_FORMAT"
Case 28: emsg = "ERROR_INTERNET_ITEM_NOT_FOUND"
Case 29: emsg = "ERROR_INTERNET_CANNOT_CONNECT"
Case 30: emsg = "ERROR_INTERNET_CONNECTION_ABORTED"
Case 31: emsg = "ERROR_INTERNET_CONNECTION_RESET"
Case 32: emsg = "ERROR_INTERNET_FORCE_RETRY"
Case 33: emsg = "ERROR_INTERNET_INVALID_PROXY_REQUEST"
Case 34: emsg = "ERROR_INTERNET_NEED_UI"
Case 36: emsg = "ERROR_INTERNET_HANDLE_EXISTS"
Case 37: emsg = "ERROR_INTERNET_SEC_CERT_DATE_INVALID"
Case 38: emsg = "ERROR_INTERNET_SEC_CERT_CN_INVALID"
Case 39: emsg = "ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR"
Case 40: emsg = "ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR"
Case 41: emsg = "ERROR_INTERNET_MIXED_SECURITY"
Case 42: emsg = "ERROR_INTERNET_CHG_POST_IS_NON_SECURE"
Case 43: emsg = "ERROR_INTERNET_POST_IS_NON_SECURE"
Case 44: emsg = "ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED"
Case 45: emsg = "ERROR_INTERNET_INVALID_CA"
Case 46: emsg = "ERROR_INTERNET_CLIENT_AUTH_NOT_SETUP"
Case 47: emsg = "ERROR_INTERNET_ASYNC_THREAD_FAILED"
Case 48: emsg = "ERROR_INTERNET_REDIRECT_SCHEME_CHANGE"
Case 49: emsg = "ERROR_INTERNET_DIALOG_PENDING"
Case 50: emsg = "ERROR_INTERNET_RETRY_DIALOG"
Case 52: emsg = "ERROR_INTERNET_HTTPS_HTTP_SUBMIT_REDIR"
Case 53: emsg = "ERROR_INTERNET_INSERT_CDROM"
Case 110: emsg = "ERROR_FTP_TRANSFER_IN_PROGRESS"
Case 111: emsg = "ERROR_FTP_DROPPED"
Case 112: emsg = "ERROR_FTP_NO_PASSIVE_MODE"
'
' gopher API errors
'
Case 130: emsg = "ERROR_GOPHER_PROTOCOL_ERROR"
Case 131: emsg = "ERROR_GOPHER_NOT_FILE"
Case 132: emsg = "ERROR_GOPHER_DATA_ERROR"
Case 133: emsg = "ERROR_GOPHER_END_OF_DATA"
Case 134: emsg = "ERROR_GOPHER_INVALID_LOCATOR"
Case 135: emsg = "ERROR_GOPHER_INCORRECT_LOCATOR_TYPE"
Case 136: emsg = "ERROR_GOPHER_NOT_GOPHER_PLUS"
Case 137: emsg = "ERROR_GOPHER_ATTRIBUTE_NOT_FOUND"
Case 138: emsg = "ERROR_GOPHER_UNKNOWN_LOCATOR"
'
' HTTP API errors
'
Case 150: emsg = "ERROR_HTTP_HEADER_NOT_FOUND"
Case 151: emsg = "ERROR_HTTP_DOWNLEVEL_SERVER"
Case 152: emsg = "ERROR_HTTP_INVALID_SERVER_RESPONSE"
Case 153: emsg = "ERROR_HTTP_INVALID_HEADER"
Case 154: emsg = "ERROR_HTTP_INVALID_QUERY_REQUEST"
Case 155: emsg = "ERROR_HTTP_HEADER_ALREADY_EXISTS"
Case 156: emsg = "ERROR_HTTP_REDIRECT_FAILED"
Case 160: emsg = "ERROR_HTTP_NOT_REDIRECTED"
Case 161: emsg = "ERROR_HTTP_COOKIE_NEEDS_CONFIRMATION"
Case 162: emsg = "ERROR_HTTP_COOKIE_DECLINED"
Case 168: emsg = "ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION"
'
' additional Internet API error codes
'
Case 157: emsg = "ERROR_INTERNET_SECURITY_CHANNEL_ERROR"
Case 158: emsg = "ERROR_INTERNET_UNABLE_TO_CACHE_FILE"
Case 159: emsg = "ERROR_INTERNET_TCPIP_NOT_INSTALLED"
Case 163: emsg = "ERROR_INTERNET_DISCONNECTED"
Case 164: emsg = "ERROR_INTERNET_SERVER_UNREACHABLE"
Case 165: emsg = "ERROR_INTERNET_PROXY_SERVER_UNREACHABLE"
Case 166: emsg = "ERROR_INTERNET_BAD_AUTO_PROXY_SCRIPT"
Case 167: emsg = "ERROR_INTERNET_UNABLE_TO_DOWNLOAD_SCRIPT"
Case 169: emsg = "ERROR_INTERNET_SEC_INVALID_CERT"
Case 170: emsg = "ERROR_INTERNET_SEC_CERT_REVOKED"
Case Else: emsg = "(not a recognised error code)"
End Select
InetErrMsg = emsg
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)
-
Aug 13th, 2002, 09:27 AM
#13
Addicted Member
and the API declarations...
VB Code:
Public Const ERROR_IO_PENDING = 997
Public Const ERROR_INTERNET_EXTENDED_ERROR = 12003
Public Declare Function InternetGetLastResponseInfo Lib "wininet.dll" Alias "InternetGetLastResponseInfoA" ( _
lpdwError As Long, _
ByVal lpszBuffer As String, _
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)
-
Aug 14th, 2002, 01:44 AM
#14
Thread Starter
New Member
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?
-
Aug 14th, 2002, 06:30 AM
#15
Addicted Member
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)
-
Aug 14th, 2002, 06:42 AM
#16
Thread Starter
New Member
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...
-
Aug 14th, 2002, 06:46 AM
#17
Addicted Member
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)
-
May 19th, 2015, 01:20 AM
#18
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|