Omnis Technical Note TNEX0004 May 2011

Displaying progress in FTP Transfer

For Omnis Studio 4/5
By Michael Hufschmidt

In Omnis you can develop the functionality of an FTP Client and integrate it into your own applications. Details of how to do that are contained in the “Omnis Command Reference” manual, and by looking up the commands starting “FTP...”, including:

FTPConnect (...) Returns socket
FTPGet (socket,remoteFile,localFile) Returns errorStatus
FTPDisconnect (socket) Returns errorStatus

In that manual you will find illustrations of how you can define a method “proc” with the command

FTPSetConfig (proc) Returns status

With this method any progress in FTP transfer can be determined. In the example in the manual this information is displayed in an OK message. However, this may not be feasible during a longer ftp transfers since this OK message would pop up numerous times and the user would have to confirm it each time with a mouse click. Therefore, this tech note shows how the FTP status information can be displayed in a working message.

For this example you will need to create several classes, as follows:

  • Startup_Task: Here only a task variable is defined.
  • Code class “oServices”: in which the method FTP_Progress is defined which is called during the FTP transfer.
  • Window class “FTP_Status”: Here parameters for the connection with the FTP server are checked, where FTPConnect is executed, the files located on the server are read with FTPList, a file is selected on the server and on the local client, and the selected file will be transferred by a click on a button.

FTP classes

This tech note only describes the code for the transfer, i.e. an FTPConnect has already been executed and by this a valid socket number has been generated.

Code in the class methods

In the Startup_Task, add a Task variable called “tFTP_Window_ Ref” of the type Item Reference. With this you can talk to open window instance FTP_Status.

In the code class oServices, you need to create a method called “FTP_Progress” with three entry parameters: “pSocket”, “pTransferred” and “pToTransfer” in this order, all with the variable type Number (Long Integer). This method only contains one line of code:

Do tFTP_Window_Ref.$makeInfoText (pSocket,pTransferred,pToTransfer)

With this code the information can be passed to the appropriate method of the window instance.

In the $construct method of the window class “FTP_Status”, a reference to the window instance is defined:

Set reference tFTP_Window_Ref to $cinst

In addition, there is the method $makeInfoText() which includes the same three parameters as listed above (“pSocket”, “pTransferred” and “pToTransfer” of the type Number, Long Integer). Furthermore, an instance variable “iText” of the type Character 250 is declared in the class. The method $makeInfoText() includes the following code:

Calculate iText as con('Socket = ',pSocket,', Transferred = ',pTransferred,', To Transfer = ',pToTransfer)
Redraw working message

The most important part of the code is placed under the button which starts the real transfer (in this case an ASCII download):

Working message Working/-1073735789,¬1073735785;50;0;60 (Cancel button) {[iText]}
FTPSetConfig ('oServices/FTP_Progress')
FTPGet (iFTPSocket,pRemoteFile,pLocalFile) Returns iErrorStatus

With the first line, the working message is opened, the second line makes sure that the FTP command will call the method of the code class during the transfer. The real transfer is started in the third line of code. The working message will be closed automatically when the method behind the button is finished.

The working message will look like this; the values will continuously update during the transfer:

FTP transfer working message

The information To Transfer is only available when uploading files; during downloads the value will always be 0.

We would like to thank Frank Keck of Heiler Software AG whose question inspired us for this tech note.

Search Omnis Developer Resources


Hit enter to search