Using Win32 functions in Visual FoxPro Image Gallery
FTP Class Library (VCX) for Visual FoxPro
Sep 20, 2008.
Summary: This solution presents class library for Visual FoxPro that wraps the FTP functions from the Microsoft® Win32® Internet (WinINet) API library.
Regular price:
  Buy this solution for $50.00
Instant download link by email.

Price for subscribers:
Make payments with PayPal - it's fast, free and secure!   Buy this solution for $30.00
Instant download link by email.

Contents
System Requirements
Description
Open the project
Run Gettingstarted.prg
Run GETTINGSTARTED.SCX
The source code
Methods and properties of FTP class
System Requirements     ..top
Minimal Visual FoxPro version: 8
Minimal Windows versions: XP, W2K

Watch a short screen recording showing the usage of the class library.
Description     ..top
The solution presents Visual FoxPro class library that wraps the set of FTP functions in the Microsoft® Win32® Internet (WinInet) API library.

The main class in the library (non-visual) covers basic FTP functionality like establishing connection to FTP server, sending and receiving files, deleting and renaming files and directories on FTP servers.


A visual class (container) is also included that, once dropped on a form, displays remote files and directories in ListView control.

The code is royalty free. You may modify it and include it in your Visual FoxPro applications without asking a permission from the author. Outside of your VFP applications, the class cannot be distributed or sold without permission explicitly obtained from its author.
Open the project     ..top
In VFP session open WININET project.


Wininet class library includes the following classes:
  • Ftp -- the main class in this library
  • TFile -- the storage for properties that describe a remote file on FTP server
  • Struct_win32_find_data -- a wrapper for WIN32_FIND_DATA api structure
  • shortcutmenu -- this class encapsulates shortcut menu (context menu), used by Ftp_files control
  • pchar -- implements dual functionality of the pointer and the string
  • Ftp_files -- this is simple FTP browser; drop it on a form and invoke ConnectToFtp(cHost, cUser, cPwd) method
  • Run Gettingstarted.prg     ..top
    Run GETTINGSTARTED.PRG module to test the basic functionality of the class. It connects to ibiblio.org FTP server (Guttenberg library) and reads the list of files and folders stored on the remote server.
     
    SET CLASSLIB TO wininet ADDITIVE
     
    LOCAL oFtp As ftp, nIndex
    oFtp = NEWOBJECT("ftp")
     
    cHost = "ibiblio.org"
    cUser = "anonymous"
    cPwd = "ftpclass@visualfoxpro.com"
     
    oFtp.ftpconnect(m.cHost, m.cUser, m.cPwd)
    ...
     
    * changes to active directory on the remote server
    oFtp.setcurrentdir("/incoming")
     
    * creates a cursor and storing in it list of
    * files and folders found in currently active remote directory
    IF oFtp.dirtocursor(oFtp.getcurrentdir(), '*.*')
        BROWSE NORMAL
    ENDIF
    ...
     
     
    Run GETTINGSTARTED.SCX     ..top
    Run GETTINGSTARTED.SCX form. This is simple FTP browser built on the class library.

    Table listofftps.dbf contains list of FTP servers that the browser can connect to. You can always modify this list adding new FTP servers.

    The ListView on the form displays icons for the file types based on the information retrieved from the Registry on the local computer.
    The source code     ..top
    Complete source code is included in the project. No external FLLs or DLLs are required, except WinInet.dll, which by default exists on each and every Windows computer.
    Methods and properties of FTP class     ..top
    MethodaftergetfileFires after remote file is downloaded; a placeholder.
    MethodafterputfileFires after local file is uploaded; a placeholder.
    MethodbeforegetfileFires before remote file is about to be downloaded; a placeholder.
    MethodbeforeputfileFires before local file is about to be uploaded; a placeholder.
    MethodclearerrorResets ERRMSG and LASTERR properties.
    MethodconnectedReturns True if connected to remote server.
    MethodcreatedirCreates the specified directory on remote server.
    MethoddeletefileDeletes the specified remote file. Wildcards cannot be used.
    MethoddirexistsReturns True if the specified directory exists on remote server.
    MethoddirtocursorCreates a cursor and populates it with file names, datetimes and attributes for the specified directory on remote server. File mask and [directories only] flag can be applied.
    MethodexecftpcommandExecutes raw FTP command; for example: STAT, USER, MDTM
    MethodfileexistsReturns True if the specified file exists on remote server.
    MethodftpconnectOpens connection to FTP server.
    MethodftpdisconnectCloses connection to FTP server.
    MethodgetcurrentdirReturns the name of current directory on FTP server.
    MethodgetfilesCalls DIRTOCURSOR method that populates a cursor with file names, datetimes and attributes for the specified directory on FTP server. Same data as in the cursor is packed into FILES collection. The me
    MethodgetfromftpDownloads remote file to local file. Names can be different. Wildcards cannot be used.
    MethodgethostReturns host name used to establish current FTP connection.
    MethodgetmodifiedfiletimeReturns last modification time for the specified remote file through call to FtpCommand API. The result can be different from one obtained via GetFiles method.
    MethodgetremotesizeReturns the size in bytes for the specified remote file through FtpCommand API call.
    MethodgetserverhelpIf a command is given, returns help on that command; otherwise, returns general help for the FTP server (usually a list of supported commands).
    MethodgetserverstatusReturns general status information about the FTP server.
    MethodgetserversystemReturns a word identifying the system on connected FTP server, the word "Type:", and the default transfer type.
    MethodgettemppathReturns temporary directory obtained through GetTempPath API call.
    MethodgetupdirReturns parent directory for the active directory on FTP server.
    MethodgetuserReturns user name used to establish current FTP connection.
    MethodongetchunkFires upon a portion of remote file is downloaded. Input parameter ChunkSize has to be supplied in GETFROMFTP call.
    MethodonputchunkFires upon a portion of local file is upnloaded. Input parameter ChunkSize has to be supplied in PUTTOFTP call.
    MethodputtoftpUpnloads local file to remote file. Names can be different. Wildcards cannot be used.
    MethodremovedirDeletes the specified remote directory.
    MethodrenamedirRenames the specified remote directory.
    MethodrenamefileRenames the specified remote file. Wildcards cannot be used.
    MethodsetaccessedfiletimeSets last access datetime for the specified local file.
    MethodsetcreatedfiletimeSets creation datetime for the specified local file.
    MethodsetcurrentdirSets active directory on FTP server.
    MethodsetfiletimeSets the date and time that a local file was created, or last accessed, or last modified.
    MethodsetmodifiedfiletimeSets last modification datetime for the specified local file.
    Methodbuf2dwordConverts a binary character representation to a numeric value. Equivalent to CTOBIN(num, "4R") in VFP9
    MethoddeclareDeclares all required API calls.
    Methoddtime2ftimeConverts VFP Datetime format to Windows API filetime format
    Methodgetfromftp1Called inside GETFROMFTP method to download a portion of remote file.
    MethodgetlocalsizeReturns the size in bytes for the specified local file.
    MethodgettimezonebiasCalculates time zone bias; required for adjusting file dates to local time zone
    Methodnum2wordConverts a numeric value to a binary character representation. Equivalent to BINTOC(num, "4R") in VFP9
    Methodputtoftp1Called inside PUTTOFTP method to upnload a portion of local file.
    MethodseterrorPopulates ERRMSG and LASTERR properties by calling GetLastError() and InternetGetLastResponseInfo() API.
    MethodsetgenericerrorSets a generic error by populating ERRMSG and LASTERR properties.
    MethodsetnotconnectedSets generic error (-1, "Not connected to FTP")
    PropertyerrmsgLast error message; string.
    PropertyfilesCollection of Tfiles objects presenting the files in specified remote directory. Populated in GetFiles method.
    Propertyftpcommand_responseA response from last call to ExecFtpCommand method; string.
    Propertyftpcommand_responsecodeA response code from last call to ExecFtpCommand method; string. Example: 213
    PropertyisconnectedReturns True if a connection to FTP server has been established.
    PropertylasterrLast error number. Stores either internal code, or value returned by GetLastError API.
    Propertysetfiletime_applybiasDefines if the Time Zone Bias is applied when setting file time for local files. True or False.
    Propertysetfiletime_ondownloadDefines if local file times are set by remote file times when downloading files. True or False.
    PropertysortkeyDefines sorting of remote files when they are enumerated: by name, by type, by size, by last modified date
    PropertysortorderDefines sorting of remote files when they are enumerated: ascending or descending
    PropertytimezonebiasDifference in minutes between GMT and local time on local computer. Populated from GetTimeZoneInformation API call during INIT.
    PropertyappversionCurrent version of this class.
    PropertyhconnValue returned by InternetConnect API call.
    PropertyhinternetValue returned by InternetOpen API call.
    PropertyhostFTP Host name
    PropertyusrUser name for current FTP connection.
    Sep 20, 2008.
    Regular price:
      Buy this solution for $50.00
    Instant download link by email.

    Price for subscribers:
    Make payments with PayPal - it's fast, free and secure!   Buy this solution for $30.00
    Instant download link by email.


    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.226.79.204)
    3 sec.Function: 'LogonUser'
    52.27 min.Example: 'Obtaining some properties for the Windows desktop using the GetWindowPlacement function'
    52.37 min.Example: 'Reading the structure of VFP main menu'
    Google
    Advertise here!