Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP connection with Win API does not return error

Status
Not open for further replies.

masterm

Programmer
Jan 25, 2002
13
ZA
Hi,

Im using windows API to connect to the internet. When I call the API InternetConnect to connect to the site and there is an error, no error code is returned from the GetLastError API and the InternetGetLastResponseInfo API has not data returned either. Why is this?

How can I determine if the password, username, or FTP site is valid if no response it given. Is there a way that I can get the error code, should the Internetconnect API fail for some Reason?

I am using VFP 8 on Win XP and Win 2000
Thanks

 
masterm

Use something like this (hFTPSession in order to be connected should give you a numeric value other than 0, otherwise, you are not connected - or an error in your case)
Code:
hFtpSession = InternetConnect (hOpen, strHost,;
	INTERNET_INVALID_PORT_NUMBER,;
	strUser, strPwd,;
	INTERNET_SERVICE_FTP, 0, 0)

If hFtpSession = 0
	= InternetCloseHandle (hOpen)
	? "Error unable to connect to the selected FTP"
	Return
Else




Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Use the GetLastError API function. Borrowing from Mike's code above...
Code:
DECLARE INTEGER GetLastError IN WIN32API

If hFtpSession = 0
    = InternetCloseHandle (hOpen)
    ? GetLastError()
    Return
Else
...

...that'll give you the error number anyways. You could take it a step further (and you might want to) and use that error number for being able to call the API function InternetGetLastResponseInfo. That's what you'll want if you want to know what the server said was up. Something like this...
Code:
DECLARE INTEGER GetLastError IN WIN32API

If hFtpSession = 0
    = InternetCloseHandle (hOpen)
    ? GetLastNetResponse(GetLastError())
    Return
Else
...

FUNCTION GetLastNetResponse(tnError)
LOCAL lcReturn, lnRetVal

DECLARE INTEGER InternetGetLastResponseInfo IN WININET.DLL ;
    INTEGER @lpdwError, STRING @lpszBuffer, INTEGER @lpcbSize 

lcErrMsg = SPACE(1024)
lnSize = 1024

lnRetVal = InterNetGetLastResponseInfo(@tnError,@lcErrMsg,@lnSize)

IF lnSize < 2
   lcReturn = ""
ELSE
   lcReturn = SUBSTR(lcErrMsg,1,lnSize)
ENDIF

RETURN lcReturn
ENDFUNC

boyd.gif

craig1442@mchsi.com
&quot;Whom computers would destroy, they must first drive mad.&quot; - Anon​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top