Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Retrieving information about the main VFP window
Using custom Simple MapiSendMail class
Using NetWkstaTransportEnum to obtain MAC Address of remote server
A client for testing non-blocking Winsock server
GDI+ fun: roach-infested desktop
Printing text on the client area of the main VFP window
Retrieving configuration information for the specified workstation (Win2000/XP)
Retrieving current settings for an ODBC connection
Storing registration key in the resources of an executable file
Accessing LSA Policy object (Local Security Authority)
GDI+: printing vertical text on VFP reports via generated images (VFP9)
Removing FTP directory
Changing file attributes
How to print picture stored in enhanced-format metafile (*.emf)
Obtaining provider name for a specific type of network
Reading metrics for the currently selected font
Retrieving the name and type of all available RAS-capable devices
Using the SetErrorMode for determining if a floppy drive is ready
How to create a desktop shortcut (shell link)
How to position the GETPRINTER() dialog
How to upload a local file to FTP server using FtpPutFile
Reading VFP settings from the Windows Registry
Retrieving list of files on the FTP directory
Yet another modal dialog: now HTML-based
Retrieving size of a remote file

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
 
#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 GENERIC_READ 0x80000000
#DEFINE GENERIC_WRITE 0x40000000
 
    PUBLIC hOpen, hFtpSession
    DO decl
 
    IF connect2ftp ("ftp.???.???", "???", "???")
        lcRemoteFile = "fpttest/win32api.txt"
 
        hFile = FtpOpenFile(hFtpSession, lcRemoteFile,;
                GENERIC_READ, FTP_TRANSFER_TYPE_BINARY, 0)
 
        IF hFile <> 0
            LOCAL lnSizeHigh
            lnSizeHigh = 0
            ? "Remote file size:", FtpGetFileSize (hFile, @lnSizeHigh)
            = InternetCloseHandle (hFile)
        ENDIF
 
        = InternetCloseHandle (hFtpSession)
        = InternetCloseHandle (hOpen)
    ENDIF
 
PROCEDURE  decl
    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
RETURN
 
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.
    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.
 
 

User rating: 10/10 (2 votes)
Rate this code sample:
  • ~
2105 bytes  
Created: 2001-07-25 12:00:00  
Modified: 2011-05-09 13:22:28  
Visits in 7 days: 117  
Listed functions:
FtpGetFileSize
FtpOpenFile
InternetCloseHandle
InternetConnect
InternetOpen
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.
Word Index links for this example:
Translate this page:
  Spanish    Portuguese    German    French    Italian  
FreeTranslation.com 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?

Thanks
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-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 (54.235.20.17)
3 sec.Example: 'How to make the caption of a VFP application flashing in the Windows task bar'
5.75 hrs.
Function group: 'Shell Lightweight Utility APIs -- Path Functions'
8.1 hrs.Example: 'Using Change Notification Objects to monitor changes to the printer or print server'
 Function: 'WNetEnumResource'
11.12 hrs.Function: 'GetForegroundWindow'
 Example: 'Current keyboard type'
1 day(s)Function: 'GdipSetWorldTransform'
 Function: 'MessageBoxIndirect'
 Example: 'How to change display settings: screen resolution, screen refresh rate'
 Function: 'PrintDlg'
Google
Advertise here!