Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to retrieve the size of a remote file (FTP)
PocketPC: custom RAPI class for executing routines on remote Windows CE device
Starting a dialog box for connecting to network resources and passing input parameters
Starting an external application in VFP using WinExec
Converting command-line string to a set of Unicode argument strings
Creating a device context for the specified printer
Displaying bitmap using the AlphaBlend function
Enumerating ports that are available for printing on a specified server
Establishing connection using the SQLDriverConnect
Getting a bit more than the _CLIPTEXT offers
How to display the Print property sheet
Testing an ODBC connection for supporting specific functionality
Using FtpCommand
Winsock: reading email messages (POP3, port 110)
Enumerating the subkeys of a user-specific key
Setting properties of the window: caption and user-defined value
Shortcut Menu Class
Using the GetTempFileName
Adding and deleting User Accounts
Creating the Save dialog box to specify the drive, directory, and name of a file to save
How to suspend or hibernate your system
Obtaining list of tables stored in an ODBC Data Source
Obtaining physical parameters for a drive: sectors, clusters, cylinders...
Retrieving file information for the VFP executable running
How to retrieve the size of a remote file (FTP)

User rating: 10/10 (2 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
click to open
Before you begin:
See also:
  • How to retrieve the size of a local file
    #DEFINE GENERIC_READ 0x80000000
    #DEFINE GENERIC_WRITE 0x40000000
        PUBLIC hOpen, hFtpSession
        DO declare
        IF connect2ftp ("ftp.???.???", "???", "???")
            lcRemoteFile = "fpttest/win32api.txt"
            hFile = FtpOpenFile(hFtpSession, lcRemoteFile,;
            IF hFile <> 0
                LOCAL lnSizeHigh
                lnSizeHigh = 0
                ? "Remote file size:", FtpGetFileSize (hFile, @lnSizeHigh)
                = InternetCloseHandle (hFile)
            = InternetCloseHandle (hFtpSession)
            = InternetCloseHandle (hOpen)
    PROCEDURE declare
        DECLARE INTEGER InternetOpen IN wininet;
            STRING sAgent, INTEGER lAccessType,;
            STRING sProxyName, STRING sProxyBypass, STRING lFlags
        DECLARE INTEGER InternetCloseHandle IN wininet INTEGER hInet  
        DECLARE INTEGER InternetConnect IN wininet;
            INTEGER hInternetSession, STRING sServerName,;
            INTEGER nServerPort, STRING sUsername, STRING sPassword,;
            INTEGER lService, INTEGER lFlags, INTEGER lContext
        DECLARE INTEGER FtpOpenFile IN wininet; 
            INTEGER hFtpSession, STRING sFileName,; 
            INTEGER lAccess, INTEGER lFlags, INTEGER lContext 
        DECLARE INTEGER FtpGetFileSize IN wininet;
            INTEGER hFile, INTEGER @lpdwFileSizeHigh
    FUNCTION  connect2ftp (strHost, strUser, strPwd) 
        * open access to Inet functions  
        hOpen = InternetOpen ("w32rmsize",;
                INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0)  
        IF hOpen = 0  
            ? "Unable to get access to WinInet.Dll"
            RETURN .F.
        * connect to FTP
        hFtpSession = InternetConnect (hOpen, strHost,;
            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.
            ? "Connected to " + strHost + " as: [" + strUser + ", *****]"
    RETURN .T.

    User rating: 10/10 (2 votes)
    Rate this code sample:
    • ~
    2110 bytes  
    Created: 2001-07-25 12:00:00  
    Modified: 2013-09-10 16:31:12  
    Visits in 7 days: 103  
    Listed functions:
    Printer friendly API declarations
    My comment:
    The code does not process the high-order part lpdwFileSizeHigh. Process this part for obtaining sizes of files larger than 4 GBytes.

    * * *
    2013-Jul-08: WebRequestMethods.Ftp.GetFileSize fails with error 550: SIZE not allowed in ASCII mode.

    Apparently there is no way to make the FtpWebRequest to send the TYPE I command before the SIZE ?.
    Word Index links for this example:
    Translate this page:
      Spanish    Portuguese    German    French    Italian offers instant, free translations of text or web pages.
    User Contributed Notes:
    Bill Coupe | 2006-07-27 09:40:21
    This works great on standard FTP sites, however when FTP'ing from a mainframe (IBM 3390) the function always returns zero (0)...

    Any ideas/functions for discovering the size of the remote file in this situation?

    A.M. | 2006-07-27 11:41:00
    Bill, I'm afraid this is how FTP protocol is implemented on mainframe's side.

    You may try using raw FTP command SIZE via FtpCommand or Winsock calls. Though I'm afraid that FtpGetFileSize is just a wrapper around this one.
    Bill Coupe | 2006-07-31 10:29:34
    Yep... I discovered that the 'info' is sort of returned in terms of blocks, blocksize and record size and that an 'estimate' is possible but not an exact value.

    Frustrating, but, not the end of the world!

    Copyright 2001-2017 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.6.38), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (
    15 sec.Login
    29 sec.Function: 'CryptGetHashParam'
    Function group: 'Cryptography Reference'
    43 sec.Function: 'CryptImportKey'
    Function group: 'Cryptography Reference'
    57 sec.Function: 'CeGetVersionEx'
    Function group: 'Remote Application Programming (RAPI)'
    1.2 min.Gallery
    1.45 min.Function: 'GetCurrentThread'
    Function group: 'Process and Thread'
    1.72 min.Function: 'SCardGetProviderId'
    Function group: 'Authentication'
    1.97 min.Function: 'NetMessageNameAdd'
    Function group: 'Network Management'
    2.17 min.Function: 'SetFileAttributes'
    Function group: 'File Management'
    2.4 min.Function: 'GdipGetDpiX'
    Function group: 'GDI+ Graphics'
    Advertise here!