Class FTPClient() Professional

Class function of the FTPClient class

Description

Instances of the FTPClient class are used to access an FTP server via the File Transfer Protocol. This communication protocol allows for exchanging the contents of arbitrary files between a client computer and a remote server in the Internet. A prerequisite for successfully using the FTPClient class is that Username and Password for accessing an FTP server are known. A connection to an FTP server fails without proper authentication.

Operations such as getting a file or changing the current directory can only be performed sequentially per session. Consequently, the corresponding methods are SYNC methods and hence are serialized between threads. If concurrent operations against the same FTP server are required in an application, a new connection must be initiated from another thread using a separate FTPClient object.

Class methods
:new()
Creates an instance of the FTPClient class.
Connection
:connect()
Connects to the FTP server.
:disconnect()
Disconnects from the FTP server.
File management
:delete()
Removes a file from the FTP server.
:get()
Retrieves the contents of a file located on the FTP server.
:getFile()
Download a file from the FTP server.
:put()
Writes a character string into a file on the FTP server.
:putFile()
Upload a file to the FTP server.
:setTransferMode()
Set the mode with which the transfer is performed.
Directory management
:createDir()
Create a directory on the FTP server.
:curDir()
Determine or change the current directory on the FTP server.
:directory()
Fills an array with information about the files in a specified path.
:removeDir()
Remove a directory on the FTP server.
Examples
Uploading and Downloading files
// The example demonstrates the programming pattern 
// for uploading or downloading files to/from 
// an FTP server. 

#pragma Library( "ASINet10.lib" ) 

PROCEDURE Main 

   LOCAL cFtpServer := "my_ftpserver.com" 
   LOCAL cUserName  := "my_Username" 
   LOCAL cPassword  := "my_password" 
   LOCAL oFtp, cContents 

   oFtp := FTPClient():new( cFtpServer, cUserName, cPassWord ) 

   IF .NOT. oFtp:connect() 
      ? "Unable to establish connection to:" , cFtpServer 
      QUIT 
   ENDIF 

   cContents := Memoread( "c:\filename.txt" ) 

   // Uploading file contents 
   IF .NOT. oFtp:put( "ftp_dir\filename.txt", cContents ) 
      ? "Unable to transfer file contents" 
   ELSE 
      // Downloading file contents 
      ? oFtp:get( "ftp_dir\filename.txt" ) 
   ENDIF 

   oFtp:disconnect() 

RETURN 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.