by Todd G. Nist
Program source is available for download: winftp.w. Modified 20 July 2000.
This program demonstrates common FTP functionality: connect to an FTP server, list directory contents, change the current directory and of course: get, put and delete files.
See also FileDownload.
The code functions as follows:
* By default, it will connect to ftp.progress.com when you press the Connect FTP button.
* Once on the site, if you double click a directory in the directory selection list, it will open that directory and display the contents.
* By selecting the appropriate button, put, get, delete, you can achieve the desired request. These are all based on having permissions to the web site.
The function FtpFindFirstFile can only be invoked once within a given FTP Session. Therefore, when a double click occurs on the directory selection list, the current FTP session is closed, and then a new one established and the function FTPDirList invoked. This function is similar to the FindFirstFile and FindNextFile win32 API calls.
No username or password are used when connecting to the FTP server. This means the default username ("anonymous") and default password (something like "IE40USER@") will be used. This will probably not give you enough permissions to put or delete items. You may have to pass more specific username and password parameters in function InternetConnectionA.
The program has been tested under NT 4.0 with service pack 3 and IE4 or IE5, and also under Windows 98 with IE5.
----
API-procedures used in this example are listed here to be included in the search index:
PROCEDURE InternetConnectA EXTERNAL "wininet.dll" PERSISTENT: PROCEDURE InternetGetLastResponseInfoA EXTERNAL "wininet.dll" PERSISTENT: PROCEDURE InternetOpenUrlA EXTERNAL "wininet.dll" PERSISTENT: PROCEDURE InternetOpenA EXTERNAL "wininet.dll" PERSISTENT: PROCEDURE InternetReadFile EXTERNAL "wininet.dll" PERSISTENT: PROCEDURE InternetCloseHandle EXTERNAL "wininet.dll" PERSISTENT: PROCEDURE FtpFindFirstFileA EXTERNAL "wininet.dll" PERSISTENT: PROCEDURE InternetFindNextFileA EXTERNAL "wininet.dll" PERSISTENT: PROCEDURE FtpGetCurrentDirectoryA EXTERNAL "wininet.dll" PERSISTENT: PROCEDURE FtpSetCurrentDirectoryA EXTERNAL "wininet.dll" PERSISTENT: PROCEDURE FtpOpenFileA EXTERNAL "wininet.dll" PERSISTENT: PROCEDURE FtpPutFileA EXTERNAL "wininet.dll" PERSISTENT: PROCEDURE FtpGetFileA EXTERNAL "wininet.dll" PERSISTENT: PROCEDURE FtpDeleteFileA EXTERNAL "wininet.dll" PERSISTENT:
winftp.w.zip : demo program