Winsock: retrieving directory listing from an FTP server using passive data connection (FTP, port 21)
User rating: 0/10 (0 votes)
Before you begin: This example shows how to connect to an FTP server using the anonymous access, and then establishing passive mode data connection to retrieve a directory listing.
Related exampleSee also:
Wininet: custom FTP class
Complete FTP solution:
Members area. Log in to view this example.
User rating: 0/10 (0 votes) 7756 bytes Created: 2003-02-16 19:17:30 Modified: 2010-01-02 14:40:52 Visits in 7 days: 73 Listed functions: My comment: There is an article I would like to recommend -- Secrets of FTP -- on the VBIP site.
It has been written for VB programmers learning how to use the Winsock control. Even if we are bound to Winsock API functions in Visual FoxPro, this article contains essential information for FTP programming with Winsock API.
For downloading a file from the server change LIST to RETR command accompanied with a remote file name. The program code is very basic with a limited error checking, so may be start with downloading small files.
FTP is an unusual service in that it utilizes two ports, a "data" port and a "command" port (also known as the control port). Another article I want to recommend is Active FTP vs. Passive FTP, a Definitive Explanation by Jay Ribak.
* * *
To create a passive data connection to an FTP server with WinINet, use INTERNET_FLAG_PASSIVE for dwFlags parameter in the InternetConnect call:
#DEFINE INTERNET_INVALID_PORT_NUMBER 0
#DEFINE INTERNET_SERVICE_FTP 1
#DEFINE INTERNET_FLAG_PASSIVE 0x08000000
nFlags = INTERNET_FLAG_PASSIVE && use 0 for the active mode
hConnection = InternetConnect(m.hInternet, m.host,;
m.usr, m.cPsw, INTERNET_SERVICE_FTP, m.nFlags, 0)
#kwd: sln_ftp, sln_winsock Word Index links for this example:
Translate this page:
Copyright © 2001-2018
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.
PHP (4.4.9), an HTML-embedded scripting language,
MySQL (5.6.39), the Open Source standard SQL database,
Version 4, freeware HTML Editor of choice. Hosted by Korax Online Inc.