Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to obtain Content-Type value for a file type from the System Registry
Listing INF files in a specified directory
Obtaining a handle to the desktop associated with the calling thread
Uploading file to the FTP server using InternetWriteFile
Using Beep and Sleep functions to make the old tin buzz sing (WinNT only?)
Accessing examples contained in this reference through Web Services
GDI+: Using Scale and Shear transformations
How to empty the Recycle Bin
How to intercept window messages sent to VFP form
Retrieving list of Global Atom names
Retrieving System Error message strings
Enumerating files opened on the network
Validating the heap of the calling process
Accessing examples contained in this reference from a VFP application
Converting path to original case
GDI+: cropping images
Number of clipboard formats available
Retrieving the state of your Internet connection
System Image List Viewer
Using FrameRgn for displaying system colors
Using GetSysColor
CryptoAPI: retrieving list of providers
Deleting a file stored on the FTP server
FindText -- the hopeless and useless Common Dialog
Reading Internet Query options

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
 
#DEFINE INTERNET_INVALID_PORT_NUMBER  0 
#DEFINE INTERNET_OPEN_TYPE_DIRECT     1 
#DEFINE INTERNET_SERVICE_FTP          1 
#DEFINE FTP_TRANSFER_TYPE_ASCII       1 
#DEFINE FTP_TRANSFER_TYPE_BINARY      2 
 
#DEFINE INTERNET_OPTION_CONNECT_TIMEOUT     2
#DEFINE INTERNET_OPTION_RECEIVE_TIMEOUT     6
#DEFINE INTERNET_OPTION_SEND_TIMEOUT        5
#DEFINE INTERNET_OPTION_USERNAME            28
#DEFINE INTERNET_OPTION_PASSWORD            29
#DEFINE INTERNET_OPTION_VERSION             40
#DEFINE INTERNET_OPTION_PROXY_USERNAME      43
#DEFINE INTERNET_OPTION_PROXY_PASSWORD      44
#DEFINE INTERNET_OPTION_CONNECTED_STATE     50
#DEFINE INTERNET_OPTION_CLIENT_CERT_CONTEXT 84
    DO decl
 
    PRIVATE hOpen, hFtpSession
    STORE 0 TO hOpen, hFtpSession
 
    IF connect2ftp("ftp.linux.com", "anonymous",;
            "vfp"+LEFT(SYS(3),5)+"@win32.com") 
        ? GetFtpStatus (hFtpSession)
        ? GetUserData (hFtpSession)
        = InternetCloseHandle (hFtpSession)  
        = InternetCloseHandle (hOpen) 
    ENDIF 
* end of main
 
FUNCTION GetFtpStatus(hConnection)
    LOCAL lcBuffer, lnBufsize
    lcBuffer = " "
    lnBufsize = 0
    IF ReadOption(hConnection, INTERNET_OPTION_CONNECTED_STATE,;
        @lcBuffer, @lnBufsize)
        RETURN (LEFT(lcBuffer,1) = Chr(1))
    ENDIF
RETURN .F.
 
FUNCTION GetUserData(hConnection)
    LOCAL lcBuffer, lnBufsize, lcResult
 
    lnBufsize = 64
    lcBuffer = " "
    = ReadOption(hConnection, INTERNET_OPTION_USERNAME,;
        @lcBuffer, @lnBufsize)
    lcResult = LEFT(lcBuffer, lnBufsize)
 
    lnBufsize = 64
    lcBuffer = " "
    = ReadOption(hConnection, INTERNET_OPTION_PASSWORD,;
        @lcBuffer, @lnBufsize)
    lcResult = lcResult + ", " + LEFT(lcBuffer, lnBufsize)
RETURN  lcResult
 
FUNCTION ReadOption(hConnection, lnOption, lcBuffer, lnBufsize)
    LOCAL lnResult
    IF TYPE("lnBufsize")<>"N" Or lnBufsize<=0
    * this call determines the buffer size needed
        = InternetQueryOption(0, lnOption, @lcBuffer, @lnBufsize)
    ENDIF
 
    * read the option
    lcBuffer = REPLI (Chr(0), lnBufsize)
RETURN InternetQueryOption(hConnection, lnOption, @lcBuffer, @lnBufsize) = 1
 
FUNCTION connect2ftp(strHost, strUser, strPwd) 
    * open access to Inet functions  
    hOpen = InternetOpen ("vfp", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0)  
 
    IF hOpen = 0  
        ? "Unable to get access to WinInet.Dll" 
        RETURN .F. 
    ENDIF 
 
    * connect to FTP  
    hFtpSession = InternetConnect (hOpen, strHost, INTERNET_INVALID_PORT_NUMBER,;  
        strUser, strPwd, INTERNET_SERVICE_FTP, 0, 0)  
 
    IF hFtpSession = 0  
    * close access to Inet functions and exit  
        = InternetCloseHandle (hOpen)  
        ? "FTP " + strHost + " is not available" 
        RETURN .F. 
    ELSE
        ? "Connected to " + strHost + " as: [" + strUser + ", *****]"  
    ENDIF  
RETURN .T. 
 
PROCEDURE  decl
    DECLARE INTEGER InternetCloseHandle IN wininet INTEGER hInet
 
    DECLARE INTEGER InternetQueryOption IN wininet;
        INTEGER hInternet, INTEGER lOption,;
        STRING @sBuffer, INTEGER @lBufferLength
 
    DECLARE INTEGER InternetOpen IN wininet;
        STRING sAgent, INTEGER lAccessType, STRING sProxyName,;
        STRING sProxyBypass, STRING lFlags
 
    DECLARE INTEGER InternetConnect IN wininet;
        INTEGER hInternetSession, STRING sServerName,;
        INTEGER nServerPort, STRING sUsername,;
        STRING sPassword, INTEGER lService,;
        INTEGER lFlags, INTEGER lContext
 
RETURN
 
 

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
3330 bytes  
Created: 2001-07-24 12:00:00  
Modified: 2008-10-03 15:25:57  
Visits in 7 days: 65  
Listed functions:
InternetCloseHandle
InternetConnect
InternetOpen
InternetQueryOption
Printer friendly API declarations
My comment:
Here you can reach complete list of Internet Option Flags as long as presented link stays valid. The MSDN is known for its volatile links.

The testing of FTP status appears to be useful when you have connected to the FTP some time ago and want to validate the connection before exchanging data or sending commands.

INTERNET_OPTION_CLIENT_CERT_CONTEXT
This flag is not supported by InternetQueryOption. The lpBuffer parameter must be a pointer to a CERT CONTEXT structure and not a pointer to a CERT CONTEXT pointer.

If an application receives ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED, it must call InternetErrorDlg or use InternetSetOption to supply a certificate before retrying the request. CertDuplicateCertificateContext is then called so that the certificate context passed can be independently released by the application.

* * *
There is an article of Ayhan AVCI
Connecting to a HTTPS server with SSL using Wininet, sending client certificate and reading response,
which I have found recently at the Code Project. Though based on VB code it may still save your time.

#kwd: sln_http.
Translate this page:
  Spanish    Portuguese    German    French    Italian  
FreeTranslation.com offers instant, free translations of text or web pages.
User Contributed Notes:
There are no notes on this subject.


Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

Privacy policy
Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (50.17.109.248)
1.28 hrs.Function: 'StretchBlt'
Function group: 'Bitmap'
1.74 hrs.Function: 'SHGetFolderLocation'
 Example: 'URL: splitting into its component parts'
3.93 hrs.Example: 'Placing On-screen Alert on top of all windows'
3.94 hrs.Example: 'How to remove a directory that is not empty'
4.97 hrs.Function: 'CeRemoveDirectory'
Function group: 'Remote Application Programming (RAPI)'
 Example: 'An alternative way of setting Form.Closable to False'
7.64 hrs.Example: 'Retrieving the state of your Internet connection'
7.65 hrs.Function: 'CreatePipe'
12.97 hrs.Example: 'The original LoadPicture() function in VFP returns valid handles to bitmaps, icons, cursors, and metafiles'
Google
Advertise here!