File Transfer Protocol (FTP)

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 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:

Attachments : demo program


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

This fails to work, occasionally

I have used a modification of this program (thank you, Todd) for many years.
However, it has started to fail. The symptom is disconnecting the control port in the middle of a remote move file.
This started on 28th May and fails mostly during the night (NZ time).
Is any one else having this issue?

It uses wininet.dll which does not work with ie11. ie11 is not installed on the machine used for ftp.
But I still suspect wininet is using something that has changed.
Any thoughts?