You are on page 1of 4

EZFTP OLE Control Copyright 1996 Rod Hewitt

Introduction The EZFTP OLE Control encapsulates most of the functionality of an FTP client. By setting a few properties, FTP transfers can be easily done from within Visual Basic or any application that is an OCX container. Although there are many other FTP OCXes available, I wrote EZFTP after reading through the Sweeper SDK documentation released by Microsoft. Microsoft encapsulated the FTP, HTTP and Gopher protocols into a DLL provided with the SDK and EZFTP uses this DLL rather than communicating directly with WinSock. In fact, there is no WinSock code at all in EZFTP! Distribution Details EZFTP.OCX is owned and copyrighted by COOL.STF. You may use EZFTP with any application without royalties or fees. Note that this free version of EZFTP only supports synchronous operation. This means that if you request a large file from a remote FTP server, control will be returned to your application only when the transfer has completed or has failed. A Professional Edition of EZFTP.OCX is currently under development which will allow asynchronous operation, including the ability to abort a transfer and update a progress indicator by use of a progress event. The Professional Edition is not freeware and will only be distributed to licensed users. Licenses for the Professional Edition are $49.00 for the control and $99.00 for the control and source code. Send email to coolstf@intr.net if you are interested in the Professional Edition. Installation There is currently no flashy installation program, but all you need to do is: 1. 2. 3. 4. 5. Transfer EZFTP.OCX and WININET.DLL to your \Windows\System or \Winnt\System32 folder Make sure you overwrite any older version of WININET.DLL. Using versions prior to the 1/31/96 version provided in the ZIP will cause GPFs when the application ends. Make sure you have the MFC/OLE DLLs on your system Make sure MFC40.DLL is dated 10/6/95 or later Register EZFTP.OCX with the command: REGSVR32 EZFTP.OCX If you dont have the MFC/OLE DLLs or dont have the latest versions, they can be download from the COOL.STF homepage, http://www.intr.net/coolstf. Properties UserName - string Set to the user name to log on with. For anonymous transfers, set to anonymous. Password - string Set to the password to log on with. For anonymous transfers, set to an email address, for example myname@domain.com. LocalFile - string

Set to the name of the local file to be transferred to or from. For example, c:\windows\desktop\myfile.txt. RemoteFile - string Set to the name of the remote file to be transferred to or from. For example, /home/myacct/etc/stuff.txt. Binary - boolean Set as appropriate for the file transfer mode. If transferring ASCII files, should be false to allow <lf> to <cr><lf> translations when moving files between the PC and a Unix machine. If transferring binary files, set true. RemoteAddress - string Sets the address of the remote FTP server. Accepts either domain names, for example ftp.domain.com or IP addresses, for example 204.157.123.4. RemoteDirectory - string Sets or returns the directory in use on the remote FTP server. For example: MsgBox EZFTP1.RemoteDirectory might display /usr/bin/rod. To change directory on the remote server, use: EZFTP1.RemoteDirectory = /usr/barney/hate/hate/hate provided the directory exists on the remote system (doesnt every machine have a /usr/barney/hate/hate/hate directory!!). Methods Connect Opens a connection to the remote FTP server specified in RemoteAddress. Disconnect Closes the connection with the remote FTP server previously opened with Connect. You must take care to issue a Disconnect after a successful Connect. Failure to do so will leave an open FTP connection on the server. GetFile Receives the remote file specified in RemoteFile and stores it locally in the file specified by LocalFile. Overwrites the local file if it already exists. For example: EZFTP1.RemoteFile = /etc/termcap EZFTP1.LocalFile = c:\windows\desktop\termcap.txt On Error Resume Next EZFTP1.GetFile If Err <> 0 Then MsgBox Unable to get file. Error code : & Format$(Err.Number) End If

PutFile Transfers the local file specified by LocalFile to the file specified by RemoteFile on the FTP server. MkDir (Directory as string) Creates a directory specified by the string Directory on the remote FTP server. RmDir (Directory as string) Removes the directory specified by the string Directory on the remote FTP server. RenameFile (OldName as string, NewFile as string) Renames the file specified in OldName to NewFile on the remote FTP server. DeleteFile (FileName as string) Deletes the file specified in FileName on the remote FTP server. GetDirectory (FileName as string) Gets a directory listing for the remote system. Wildcards may be specified in the FileName string. Fires the NextDirectoryEvent for each file that is reported by the remote FTP server. For example: On Error Resume Next Get the directory. Work actually done in the NextDirectoryEntry event EZFTP1.GetDirectory *.* Arrive here after all possible files have been returned If Err <> 0 Then MsgBox Unable to get directory. Error: & format$(Err.Number) End If Events NextDirectoryEntry (FileName As String, Attributes As Long, Length As Double) Fires for each file that is returned by the remote FTP server after a GetDirectory method is used. FileName Contains the name of the file on the remote system Attributes Contains bit flags indicating the type of the file. Length Contains the length of the file in bytes. Error Handling The RemoteDirectory property when written to and all methods can generate runtime errors. For example,

attempting to receive a file that doesnt exist with the GetFile method will generate a runtime error. Therefore, it is important to ensure that error handling routines are provided for the methods and the RemoteDirectory property. If an error occurs, Err.Number can be set to one of the following values. The errors without an explanation should never be seen. If you do encounter one of these errors, be sure to let us know what you did to generate the error. Send email to coolstf@intr.net. 1000 1001 1002 1003 1004 1005 1006 1006 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1027 1028 1029 General Error. Out of handles. Timeout. The operation was aborted because the remote system didnt respond. Extended error. Internal error. Invalid URL. Unrecognized scheme. Name not resolved. The remote domain name couldnt be resolved. Protocol not found. Invalid option. Bad option length. Option not settable. Shutdown. Incorrect user name. The user name specified in the UserName property was not accepted by the remote system. Incorrect password. The password specified in the Password property was not accepted by the remote system. Login failure. The server didnt allow the user name / password combination. Invalid operation. Operation cancelled. Incorrect handle type. Not local handle. Not proxy request. Internet registry value not found. Bad registry parameter. No direct access. Transfer in progress. FTP connected. FTP disconnected. The remote system unexpectedly closed the connection.

Additionally, Err.Description contains an description of the error, plus any extra error information returned by the FTP interface, separated by a colon. For example: Unable to connect to FTP server: 220-Welcome to the Internet Interstate FTP server! 220220 sheldon FTP server (Version wu-2.4(1) Thu Aug 17 09:56:25 EDT 1995) ready. 331 Password required for xx. 530 Login incorrect. 221 Goodbye.