|
|
EsFtp - ActiveX ControlEurosource, Gruvbyn 415, S-820 50 LOOS, Sweden With this control you can handle all aspects of the client side part of the ftp-protocols. Unlike many other products on the market this control is built from the ground up and is not dependent on any OS dll's except for the MFC runtime libraries. EsFtp can move files from a client to a server or vice versa. The control can delete libraries or files on the server.
InstallationTransfer EsFtp32.ocx to your \windows\system or \winnt35\system32 directory and register it by executing the command: RegSvr32 \Windows\System\EsFtp32.ocxRegSvr32.exe can be found on the Visual Basic 4.0 CD-ROM and in our dll archive (www.eurosource.se). If RegSvr32.exe fails, it's probably because you don't have the MFC 4.0 DLL library installed on your system. This is available from many sources on the Internet including our ftp archive as MFCDLLS.ZIP. Regsvr32.exe is also included in this archive. If you want to check if you already got the files in mfcdlls.zip they are
Cookbook or how to use the EsFtp ControlCreate a EsFtp object for an ASP applicationUse the object ID ESFTP.EsFtpCtrl.1 when you create an instance of the
EsFtpCtrl. Connecting to an ftp-serverUse the following code to start a session with an ftp server. There is no need to set the port in code as this already is the default value but it is shown here for completeness. The lblStatus is just a text label on the form that gives the user some information about what is going on.
Get the directory contents of a remote serverIn this code fragment we retrive the remote directory structure when a button is clicked. When the button is clicked the cmdGetRemoteDir_Click() subroutine gets called. This routine clears two listboxes, ListDirs which is used for drectories and ListFiles which is used for files. I also add the "current directory" and "up an level" tokens in the directory listbox. The call to the GetRemoteDirFile method get a file containing the directory structure as its return value. If this is a file have a valid path in it you have the directory structure in that file if not some error have occured. You can parse this file yourself for information about the returned directory or you can use the DirectoryLine event which is a convenient way to interpret the directory content. Private Sub cmdGetRemoteDir_Click() This sub is hooked to the DirectoryLine event which is called ones for every directory line returned from the server. In this subroutine we just fill directories names in the directory listbox and filenames in the filenames listbox. Private Sub EsFtp1_DirectoryLine(ByVal fDir As Boolean, ByVal
Name As String, ByVal Size As Long)
Properties
BOOL bExtractDateNormally DirectoryLine events are fired when a directory is fetched. If you set this flag to true DirectoryLineEx events is fired instead. This event also give the date information.
long ErrorNoRead only. Holds the last generated error-code. If you get a False return value form a method you should always check the ErrorNo property to determine the cause for the error. There are two types of error messages. One type is the ftp reply codes and one is the WinSock error codes. Ftp reply codes-1 General Error. WinSock error codes10013 - WSAEACCES, Permission denied. 10048 - WSAEADDRINUSE, Address already in use. 10049 - WSAEADDRNOTAVAIL, Cannot assign requested address. 10047 - WSAEAFNOSUPPORT, Address family not supported by protocol family. 10037 - WSAEALREADY, Operation already in progress. 10053 - WSAECONNABORTED, Software caused connection abort. 10061 - WSAECONNREFUSED, Connection refused. 10054 - WSAECONNRESET, Connection reset by peer. 10039 - WSAEDESTADDRREQ, Destination address required. 10014 - WSAEFAULT, Bad address. 10064 - WSAEHOSTDOWN, Host is down. 10065 - WSAEHOSTUNREACH, No route to host. 10036 - WSAEINPROGRESS, Operation now in progress. 10004 - WSAEINTR, Interrupted function call. 10022 - WSAEINVAL, Invalid argument. 10056 - WSAEISCONN, Socket is already connected. 10024 - WSAEMFILE, Too many open files. 10040 - WSAEMSGSIZE, Message too long. 10050 - WSAENETDOWN, Network is down. 10052 - WSAENETRESET, Network dropped connection on reset. 10051 - WSAENETUNREACH, Network is unreachable. 10055 - WSAENOBUFS, No buffer space available. 10042 - WSAENOPROTOOPT, Bad protocol option. 10057 - WSAENOTCONN, Socket is not connected. 10038 - WSAENOTSOCK, Socket operation on non-socket. 10045 - WSAEOPNOTSUPP, Operation not supported. 10046 - WSAEPFNOSUPPORT, Protocol family not supported. 10067 - WSAEPROCLIM, Too many processes. 10043 - WSAEPROTONOSUPPORT, Protocol not supported. 10041 - WSAEPROTOTYPE, Protocol wrong type for socket. 10058 - WSAESHUTDOWN, Cannot send after socket shutdown. 10044 - WSAESOCKTNOSUPPORT, Socket type not supported. 10060 - WSAETIMEDOUT, Connection timed out. 10035 - WSAEWOULDBLOCK, Resource temporarily unavailable. 11001 - WSAHOST_NOT_FOUND, Host not found. (OS dependent) - WSA_INVALID_HANDLE, Specified event object handle is invalid.
(OS dependent) - WSA_INVALID_PARAMETER, One or more parameters are invalid.
(OS dependent) - WSAINVALIDPROCTABLE, Invalid procedure table from service
provider. (OS dependent) - WSAINVALIDPROVIDER, Invalid service provider version number. (OS dependent) - WSA_IO_PENDING, Overlapped operations will complete later.
(OS dependent) - WSA_IO_INCOMPLETE, Overlapped I/O event object not in signaled
state. (OS dependent) - WSA_NOT_ENOUGH_MEMORY, Insufficient memory available.
10093 - WSANOTINITIALISED, Successful WSAStartup not yet performed. 11004 - WSANO_DATA, Valid name, no data record of requested type. 11003 - WSANO_RECOVERY, This is a non-recoverable error. (OS dependent) - WSAPROVIDERFAILEDINIT, Unable to initialize a service
provider. (OS dependent) - WSASYSCALLFAILURE, System call failure. 10091 - WSASYSNOTREADY, Network subsystem is unavailable. · that the appropriate Windows Sockets DLL file is in the current path, · that they are not trying to use more than one Windows Sockets implementation simultaneously. If there is more than one WINSOCK DLL on your system, be sure the first one in the path is appropriate for the network subsystem currently loaded. · the Windows Sockets implementation documentation to be sure all necessary components are currently installed and configured correctly. 11002 - WSATRY_AGAIN, Non-authoritative host not found. 10092 - WSAVERNOTSUPPORTED, WINSOCK.DLL version out of range. 10094 - WSAEDISCON, Graceful shutdown in progress. (OS dependent) - WSA_OPERATION_ABORTED, Overlapped operation aborted.
short HostTypeThis is an enumerated property that holds the host type of the remote host. The default is HOST_AUTO which determines the host type automatically.
BSTR LocalDirThe local directory is a directory on the client machine. Set this to the path of the directory you want to download files to or upload files from.
LPSTR PasswordThe password used to establish an ftp-session to a specified server for the connecting user..
long PortThe port that should be used. Normally this is 21 (the standard ftp port).
BSTR RemoteDirA directory on the remote machine. Set this property to the path on the remote machine where you want to work.
BSTR RemoteHostThis is either the name (ftp.somewhere.com) or the IP-address (192.128.0.1) of the remote machine to which you want to do a ftp-connection.
long TimeoutThis is the Time-out, in milliseconds, used when receiving/sending data from/to the ftp-server.
BSTR UserNameThis is the username on the remote machine for the connecting user.
BOOL fUniqueSet to true if you want to make certain that no files are beeing overwitten during download.
BOOL fUseFirewallThis property have no meaning at the moment.
Methods
BOOL ChangeWorkingDir(LPCTSTR Path)With this method you can change the working directory on the remote server. Just call the method with the remote-path as the only paameter. If the function return true everything is OK otherwise you should check the ErrorNo property to get the cause for the failure.
BOOL Connect()Start a ftp-session with a remote host. You should first set the desired username in the UserName property, the password in the Password property and the remote hostname in the Remotehost property. If the function return true everything is OK otherwise you should check the ErrorNo property to get the cause for the failure.
BOOL DeleteFile( LPCTSTR path )This is an alias for RemoveFile.
BOOL Disconnect()Call this method to terminate a ftp-session. If the function return true everything is OK otherwise you should check the ErrorNo property to get the cause for the failure.
BSTR GetRemoteDirFile()With this function you retrive the content of the current directory on the remote server. You use code like the following to accomblish this Dim filename as string filename = EsFtp1.GetRemoteDirFile A temporary file is received which holds the actual directory structure. If an error occurs a null length filename is returned indicating failure. In that case you should check the ErrorNo property to get the cause for the failure. You can now parse the returned file or take advantage of the DirectoryLine event which gives this information parsed for you.
BOOL GetRemoteFile(LPCTSTR RemoteName, LPCTSTR LocalName, LPCTSTR Type)Use this method to receive a file from the remote server. The RemoteName is the name of the file on the remote machine. The LocalName is the name you want for the file on your local machine. If this parameter is set to an empty string the RemoteName is used. Type can be one of the following
If the function return true everything is OK otherwise you should check the ErrorNo property to get the cause for the failure.
BSTR GetWorkingDir()Use thsi method to get the current working directory on the remote server.
BOOL MakeDir(LPCTSTR path)Use this to create a directory on the remote server. The path parameter holds the name of the directory. If the function return true everything is OK otherwise you should check the ErrorNo property to get the cause for the failure.
BOOL MkDir(LPCTSTR path)This is an alias for MakeDir.
short Quote(LPCTSTR CmdString)With this command you can send a command of your choice to the ftp-server. Just supply your command with any possible parameters in the CmdString parameter.
BOOL RenameFile(LPCTSTR oldname, LPCTSTR newname)With this command you can rename a file on the remote server. If the function return true everything is OK otherwise you should check the ErrorNo property to get the cause for the failure.
BOOL RemoveDir(LPCTSTR Path)Use this method to delete a directory on the remote server. The Path parameter holds the name of the directory. If the function return true everything is OK otherwise you should check the ErrorNo property to get the cause for the failure.
BOOL RemoveDir(LPCTSTR Path)Use this method to delete a directory on the remote server. The Path parameter holds the name of the directory. If the function return true everything is OK otherwise you should check the ErrorNo property to get the cause for the failure.
BOOL RemoveDirAndFiles(LPCTSTR Path)Use this method to delete a directory and the files in that directory on the remote server. The Path parameter holds the name of the file to delete. The method fails if the directory contains other folders. If the function return true everything is OK otherwise you should check the ErrorNo property to get the cause for the failure.
BOOL RemoveFile(LPCTSTR Path)Use this method to delete a file on the remote server. The Path parameter holds the name of the file. If the function return true everything is OK otherwise you should check the ErrorNo property to get the cause for the failure.
BOOL RmDir(LPCTSTR Path)This is an alias for RemoveDir.
BOOL SendLocalFile(LPCTSTR LocalName, LPCTSTR RemoteName, LPCTSTR Type)Use this method to trensfere a file to a remote ftp-server. The LocalName parameter holds the name of the file to transfere. RemoteName holds the name for the file on the remote server or an empty string if this is the same name as in the LocalName parameter. The type indicates the type of file
If the function return true everything is OK otherwise you should check the ErrorNo property to get the cause for the failure.
Events
DirectoryLine( BOOL fDir, LPCTSTR Name, long Size )This event is called ones for each line in a directory structure returned after a call to the GetRemoteDirFile method. The fDir parameter is set to true if the line represents a directory. The Name parameter is the directory/file name and the Size is the size (in bytes) for the file. If you want to fill information in listboxes you can use code as the following. ListDirs is a listbox holding directory information and ListFiles is a listbox holding file information. Private Sub EsFtp1_DirectoryLine(ByVal fDir As Boolean, ByVal
Name As String, ByVal Size As Long)
DirectoryLineEx( BOOL fDir, LPCTSTR Name, long Size, LPCTSTR DateStr )This event is fired instead of DirectoryLine if the bExtractDate property is set to true. This event also gives the date for the directory item.
Response( short Code, LPCTSTR Message )Every response from an ftp-server is reported in this event. The actual message is in the Message parameter and the code parameter is the numeric interpretion. You can use this event to interpret the outcome after you issue a command or just as a way to report error/success information to the user.
Status (short Mtype, long progress)Certain operations take some time to complete. This event gives you information about how much of the job that has been completed. When a lengthy job starts the status event is fired with progress set to 0 and then you get status events until the job is complete and a status event with progress set to 100 is fired. You therefore only need to write the progress to a gauge control to give your users dynamic information. The Mtype parameter have tree possible values
You can use code as the following to give the user info about the progress of a transefer Private Sub EsFtp1_Status(ByVal MType As Integer, ByVal
Progress As Long)
Additional Documentation
Where to get the control?It is possible that you are reading this documentation without having access to the control itself. If you have Internet access you just need to connect to http://www.eurosource.se and fetch a fully working sample of the control. At this location you can also find samples on how to use the control. We can email the control anywhere in the world if you send us a request to do so. Please state if you want MIME or BINHEX coding. Send request to sales@eurosource.se If you use the unregistered version of the control a splash screen is displayed from time to time reminding you to register.To get rid of this nag-screen you need to register. Information is available at our site. We ship anywhere in the world with World-wide First Class/Airmail if you select this option. The only media supported is 3.5" diskettes.The charge for this type of delivery is $15 (USD) extra. SupportYou can get support by sending email to support@eurosource.se. You can also find relevant information on-line at http://www.eurosource.se We also check the newsgroup comp.lang.basic.visual.3rdparty on a regular basis and will try to help on all questions posted there.
How to contact us
|