Tips   >   Internet   >   FTP

FTP

Omnis has a whole group of FTP commands which you can use.

FTPChmod
FTPConnect
FTPCwd
FTPDelete
FTPDisconnect
FTPGet
FTPGetBinary
FTPGetLastStatus
FTPList
FTPMkdir
FTPPut
FTPPutBinary
FTPPwd
FTPReceiveCommandReplyLine
FTPRename
FTPSendCommand
FTPSetConfig
FTPSite
FTPType

You can look up information on each of these command in the F1 Help.

The StudioTips tipBase library contains an object class called, oFTP. I use the oFTP object for uploading the StudioTips documentation to the studiotips.net website and for the AutoUpdater utility.

The oFTP object class acts as an adapter to the Omnis FTP commands, making it easy for you to setup and use FTP in your application. You don't have to study all the Omnis FTP commands. You simply use the public methods of oFTP and it executes the FTP command for you. StudioTips members are welcome to copy the oFTP object class to their own applications.

After you instantiate the oFTP object using an object datatype variable of the scope of your choice you send it an $initialize message. The $initialize message includes parameters that specify the server, user name, password, etc. Once the object has been initialized it knows the server, user name and password, so you don't need to supply that information as you call the various public methods of oFTP.

If an error occurs, the error information is copied to an iErrText ivar of the oFTP object class, and kFalse is returned to the sender. The FTP error code is looked up and the user readabble FTP error text is appended to the iErrText. An $:ErrorText method returns the current value of iErrText to the sender. The oFTP object will also check if your application uses an oErrorHandler object instantiated by the startup task variable errhndlr, and if you do, oFTP will send a $logError or $logFTPError to your error handler.

The following is some sample code of how you might use the oFTP error handler object.

Calculate ServerAddr as 'studiotips.net'
Calculate UserName as 'temp@studiotips.net'
Calculate Password as 'pass'
Calculate PortNum as ''
Calculate InitialDir as ''
Calculate PingTimeOutSeconds as 0 ;; Don't use TCPPing
; (pServerAddr,pUserName,pPassword,pPortNum_opt,pInitialDir_opt,pPingTimeoutSeconds_opt)
Do oFTP.$initialize(ServerAddr,UserName,Password,PortNum,InitialDir,PingTimeOutSeconds) Returns FlagOK
If FlagOK
   
   Do oFTP.$connect() Returns FlagOK
   If FlagOK
      
      Do oFTP.$:PathWorkingDir() Returns FolderPath
      
      Do oFTP.$:FilesList_longformat() Returns FilesList
      If FilesList.$colcount=0
         Calculate FlagOK as kFalse
      Else
         OK message oFTP Object Class (Icon) {There are [FilesList.$linecount] files and/or directories found in the [FolderPath] directory on the [ServerAddr] server for the FTP user [UserName]}
      End If
   End If
End If
If not(FlagOK)
   Do oFTP.$:ErrorText() Returns ErrText
   OK message FTP Error (Icon) {[ErrText]}
End If
Quit method FlagOK

StudioTips members are welcome to copy the oFTP object class from the tipsBase library to their own applications or download it from studiotips.net/downloads/

Click the Run Demo button in the StudioTips Browser to run the sample code.