| Lescasse Consulting |
| Home Company News Prices Download Buy Forums |
|
|
Printer Friendly
See also: TFTP5 is a non-visual object designed to help download and upload files from/to an FTP Server.
More generally it allows you to:
l navigate within the Server sub-directories l list, create, delete, rename files and directories with commands similar to DOS commands l upload files or groups of files l download files or groups of files l check a log of your FTP activities l visualize the progress of your upload and download operations l use wildcards characters (* and ?) in most method arguments
TFTP5 is particularly useful if you need to automate repetitive tasks of updating files on a remote Server, or need to programmatically move files between your applications and a remote Server.
Note that TFTP5 uses the following freeware royalty free ActiveX component: ChilkatFTP which is delivered with APL+Win Objects™. Visit http://www.chilkatsoft.com if you want to know more about ChilkatFTP.
Before you may use TFTP5, you must have properly installed APL+Win Objects™. A proper installation of APL+Win Objects™ automatically registers the ChilkatFTP.dll component.
If you are just copying the OBJECTS6.w3 workspace to another computer and want to use TFTP5 there, you should manually register the ChilkatFTP DLL.
To do so, after having loaded the OBJECTS6.w3 workspace, you should register the ChilkatFTP DLL. Register the ChilkatFTP DLL as follows:
'oo'Świ'Register' 'c:\aplwin\objects\chilkatftp.dll'
where you should replace c:\aplwin\objects with the name of the directory where you have installed APL+Win Objects™.
To create an instance of TFTP5, use the following command:
'ftp'Świ'*Create' 'TFTP5'
You need 4 pieces of information to get connected to an FTP server:
l a user name l a password l a host name l a port
You need that your user name and password be declared on the Server as a valid FTP user or you may connect with a User Name of 'Anonymous' and an empty password. Once connected, you, as an FTP User, have access to a subpart of the Server disk, starting at a given sub-directory associated with your user name.
Once these prerequisites are fulfilled, to connect to an FTP Server, use the Connect method:
Example:
'ftp'Świ'Connect' 'username' 'password' 'www.lescasse.com'
The Connect method returns 1 if you succeeded to get connected, 0 otherwise.
Note that I have replaced my real FTP user name by username and my password by password for security reasons. Be sure to not prefix the Connect method with a * since you would be calling the object native XConnect method which would break since it does not accept any argument.
It is very likely that you would like to avoid exposing your user name and password when connecting to an FTP Server. For this purpose, you might prefer to use the ConnectMe method.
The ConnectMe method assumes that you have written a User Command (or APL function) called CMDCONNECTME similar to the following one:
’ CMDCONNECTME A
where you should replace 'username' by your FTP user name and 'password' by your FTP password.
Once you have saved such a CMDCONNECTME function in your User Command File with the following command:
]usave CMDCONNECTME
you may get connected to your FTP Server with the following simple command:
'ftp'Świ'ConnectMe'
which does not expose your user name and password. As for the Connect command the ConnectMe command returns 1 if the command succeeded, 0 otherwise.
If you don't have a user account on an FTP server you may try to get connected as an anonymous user. To do so, simply use a user name of anonymous and no password.
Example:
'ftp'Świ'Connect' 'anonymous' '' 'www.genweb.net'
As an anonymous user you are however generally limited to browsing and download capabilities.
At any time you may use the isconnected property to check if you are connected to the FTP Server. This property returns 1 if you are connected, 0 otherwise.
'ftp'Świ'isconnected' 0
Use the Close or Disconnect method to disconnect from an FTP Server (both methods are equivalent):
'ftp'Świ'Disconnect'
This method does not return any result.
Please note that you do not need to disconnect before you reconnect to another Server: however this is better practice.
Example:
'ftp'Świ'Connect' 'anonymous' '' 'www.genweb.net'
As an FTP user you have access to a subpart of the Server directories starting at a given directory: this directory is called your FTP Root Directory.
You cannot see or reach any parent or sibling directory of your FTP Root Directory. In all the following examples, I'll be using one of my FTP accounts to my server. This account gives me access to the directory c:\inetpub on my server and to all of its subdirectories.
With most TFTP5 commands you may use relative or absolute files names. You may change directories on the remote server using the Chdir method. The remote directory you are in at a given time is called the current remote directory. Thus, just after having connected to an FTP Server, the current remote directory is the FTP Root Directory. In our examples it will therefore be: c:\inetpub
If I query what is the current remote directory using the Chdir method it will report it as being / because it is the Root of what I am allowed to see on the server.
'ftp'Świ'Chdir'
Let's assume there is a directory called: c:\inetpub\ftproot\ftp\temp on my server and a file named: c:\inetpub\ftproot\ftp\temp\picutil.w3
I can reach this file as follows:
'ftp'Świ'Dir' '/ftproot/ftp/temp/picutil.w3'
or:
'ftp'Świ'Dir' 'ftproot/ftp/temp/picutil.w3'
or move the current directory to the /ftproot/ftp and reach the file with a relative path starting from the /ftproot/ftp directory:
'ftp'Świ'Chdir' '/ftproot/ftp'
Although the current directory is now /ftproot/ftp (i.e. c:\inetpub\ftproot\ftp) I could still reach the file with an absolute path name:
'ftp'Świ'Dir' '/ftproot/ftp/temp/picutil.w3'
but no longer with:
'ftp'Świ'Dir' 'ftproot/ftp/temp/picutil.w3'
The Dir method returned Ż1 since I have specified a relative file name from /ftproot/ftp i.e. /ftproot/ftp/ftproot/ftp/temp/picutil.w3
If you do not feel comfortable changing remote directories and working with current directories and relative remote file names, it is advisable and safer to always use absolute file and directory names i.e. always start remote file names with a /. In our examples, this would mean always starting from the Root directory / (c:\inetpub).
You can use the Dir and Chdir methods to list files in the FTP Server remote directories and to change the current remote directory.
Example:
'ftp'Świ'dir'
This returns the current remote directory. Remember that your FTP user account already points to the directory to which you have access on the server (your FTP Root Directory). In our examples the FTP Root Directory is: C:\inetpub
'ftp'Świ'Chdir' 'ftproot'
The above examples first move the current directory to /ftproot and then reports it. After the first command the current remote directory has become: c:\inetpub\ftproot
The Chdir method returns 1 if successful and 0 otherwise.
'ftp'Świ'Chdir' 'ftproot'
Chdir returns 0 since there is no ftproot subdirectory under /ftproot.
'ftp'Świ'Chdir' 'ftp/lescasse'
We are now positioned at: c:\inetpub\ftproot\ftp\lescasse
We could have achieved the same current remote directory change in one FTP command:
'ftp'Świ'Chdir' '/ftproot/ftp/lescasse'
If you do not start the Chdir method parameter with a /, then you are moving to a directory relative to the current remote directory. Example:
'ftp'Świ'Chdir'
At any time you can use the Dir method to list existing files and sub-directories in the current remote directory:
'ftp'Świ'Dir'
The 3 numeric columns reported by Dir are:
l file size l file date l file time (sometimes 0)
Note that these columns always contain 0's for files which represent subdirectories.
The Dir command is similar to the DOS Dir command and accepts an argument with wildcard characters to select only certain files:
'ftp'Świ'Dir' '*.exe'
To create a directory on the FTP Server, use the Mkdir method.
'ftp'Świ'Chdir' '/ftproot/ftp'
In the above example we have created the following remote directory: c:\inetpub\ftproot\ftp\temp
Note that we have specified a directory (temp) relative to the current remote directory which was: c:\inetpub\ftproot\ftp
We could as well have used an absolute path starting at the FTP Root Directory:
'ftp'Świ'Mkdir' '/ftproot/ftp/temp'
To rename remote files, use the Ren method. You may not rename more than one file at a time (you cannot use wildcard characters with this method). The Ren 1st argument is the old file name and its 2nd argument is the new file name. You may use relative and/or absolute file names for both of the arguments.
Example:
'ftp'Świ'Chdir' '/ftproot/ftp'
This example renames the /ftproot/ftp/temp/picutil.w3 file to /ftproot/ftp/temp/picut.w3. Note that we have used an absolute file name for the 1st argument and a relative file name for the 2nd argument.
Deleting remote files is done by using the Del method with or without wildcard characters (* and ?) much as you would do it under DOS. The result is the number of files which have been deleted.
Examples:
'ftp'Świ'Del' '/ftproot/ftp/temp/picutil.w3'
This first example removed one file (picutil.w3) in the following remote directory: c:\inetpub\ftproot\ftp\temp
'ftp'Świ'Chdir' '/ftproot/ftp/temp'
This second example removed 2 files (Form1.frm and Form1.frx) in the following remote directory: c:\inetpub\ftproot\ftp\temp.
Note that it is recommended to always use absolute path names when removing files. This would prevent you from erasing files from the wrong directory.
'ftp'Świ'Chdir' '/ftproot/ftp'
This third example erased all remaining files (Project1.vbp, Project1.vbw and ZlibTool.ocx) in the following remote directory: c:\inetpub\ftproot\ftp\temp.
To delete remote directories, use the Rmdir method. You cannot remove a directory if it still contains files: in that case first erase its files using the Del method and then use Rmdir to remove the directory.
Example:
'ftp'Świ'Del' '/ftproot/ftp/temp/*.*'
You can use relative or absolute path naming in the Rmdir argument.
Use the Upload method to upload one or more files to the FTP server:
'ftp'Świ'Upload' 'c:\temp\picutil.w3' '/ftproot/ftp/temp/picutil.w3'
The Upload 1st argument must be the local file name and the 2nd argument the remote file name. For the remote file name you may use either relative or absolute path names. The result of the Upload method is the number of file uploaded or Ż1 if the upload failed. By default, the Upload progress percentage is displayed in the APL session.
If you have used the handler property to define a global handler function for the TFTP5 object, then the progress percentage is not displayed in the APL session but you can use the onXPutProgress event to display the progress percentage (received in Śwarg) on a progress bar, for example.
Example:
'ftp'Świ'handler' 'TFTP5_Handlers'
If you want to upload more than one file at a time you may use wildcard characters (* and ?) in the first Upload argument, but in this case the 2nd argument must be a remote file directory (not a file name).
Example:
'ftp'Świ'Upload' 'c:\temp\zipocx\*.*' '/ftproot/ftp/temp'
If the upload operation is successful the Upload method returns the number of uploaded files. If it fails, it returns Ż1.
Downloading files from the FTP Server is very similar to the uploading operation described above. Invoke the Download method to get files from the server. You may either specify one remote file name (1st argument) to download to a local file name (2nd argument) or you may use wildcard characters (* and ?) to download a group of files (1st argument) to a local directory (2nd argument).
Example:
'ftp'Świ'Download' '/ftproot/ftp/temp/picutil.w3'
'c:\temp\picutil.w3'
Just like the Upload method, the Download method returns the number of downloaded files if the operation was successful or Ż1 if it failed. By default the progress percentage is displayed in the APL session. If you have defined a handler property for the TFTP5 object, the progress percentage is not displayed in the APL session and you may use the onXGetProgress event to display it on a form, for example in a progress bar. Śwarg contains the progress percentage.
You may download more than one files to a local directory by using wildcard characters.
Example:
'ftp'Świ'download' '/ftproot/ftp/temp/*.*' 'c:\temp\zipocx'
You may obtain a list of the files and directories contained in the current remote directory in XML format by using the XmlDir method.
'ftp'Świ'Chdir' '/wwwroot/classes/cfgraphs'
'ftp'Świ'XmlDir'
You may get a complete log of all your FTP commands including errors, since your last FTP connection by using the XmlLog method.
Example:
'ftp'Świ'XmlLog'
|
|||||||||||||||||||||||
| This entire Web site has been dynamically generated by APL+Win Objects™ 6.0 For all questions contact: info@lescasse.com Copyright © 2003-2005 Lescasse Consulting. All rights reserved. |