xHarbour Reference Documentation > Class Reference (textmode) |
Creates a new TIpClientFtp object.
TIpClientFtp():new( <cUrl>, [<lTrace>] ) --> oTIpClientFtp
ftp://<userID>:<password>@<server.com>
Alternatively, a TUrl() object can be passed that is initialized with the FTP server URL.
The function returns a new TIpClientFtp object and method :new() initializes the object.
Objects of the TIpClientFtp() class inherit from the generic internet client class TIpClient(). TIpClientFtp objects are used to communicate with an FTP server. They use the File Transfer Protocol (FTP, RFC0821.TXT) for exchanging files between a local and a remote station. The address of the FTP server must be provided as a URL string with method :new(). The URL is maintained by a TUrl() object, which is stored in the :oUrl instance variable.
The internet connection to the FTP server must be established with the :open() method.
Once the internet connection is established (opened), files can be uploaded or downloaded using the :uploadFile() or :uploadFile() methods.
When all files are sent or received, the internet connection must be closed with the :close() method.
See also: | TIpClient(), TIpClientHttp(), TUrl() |
Category: | Internet functions , Object functions , xHarbour extensions |
Source: | tip\ftpcln.prg |
LIB: | lib\xhb.lib |
DLL: | dll\xhb.dll |
// The example demonstrates file transfers using an USB memory stick connected // to a WLAN server. The internet address of the WLAN server is 192.168.178.1. #include "Directry.ch" PROCEDURE Main LOCAL oFtp, cRoot LOCAL cUSBStick := "ftp://anonymous:guest@192.168.178.1" CLS oFtp := TIpClientFtp():new( cUSBStick ) // function for displaying progress bar oFtp:exGauge := ( @FtpProgress() ) IF .NOT. oFtp:open() ? oFtp:lastErrorMessage() QUIT ENDIF aFiles := oFtp:listFiles() cRoot := aFiles[1,1] ? oFtp:cwd( cRoot ), oFtp:cReply ? oFtp:mkd( "newdir" ), oFtp:cReply ? oFtp:cwd( "newdir" ), oFtp:cReply ? oFtp:uploadFile( "testftp.prg" ) , oFtp:cReply ? oFtp:uploadFile( "testftp.exe" ) , oFtp:cReply oFtp:cwd( ".." ) Dirlist( oFtp, aFiles, "" ) oFtp:cwd( cRoot + "/newdir" ) ? oFtp:downloadFile( "testftp.prg" ), oFtp:cReply ? oFtp:dele( "testftp.exe" ), oFtp:cReply ? oFtp:dele( "testftp.prg" ), oFtp:cReply ? oFtp:cwd( ".." ), oFtp:cReply ? oFtp:rmd( "newdir" ), oFtp:cReply oFtp:close() RETURN // Recurses through all directories and lists files FUNCTION DirList( oFtp, aFiles, cIndent ) LOCAL aFile FOR EACH aFile IN aFiles IF aFile[F_NAME] == "." .OR. aFile[F_NAME] == ".." LOOP ENDIF ? cIndent, aFile[F_NAME] IF aFile[F_ATTR][1] == "d" oFtp:cwd( aFile[F_NAME] ) DirList( oFtp, oFtp:listFiles(), cIndent+" " ) oFtp:cwd( ".." ) ENDIF NEXT RETURN .T. // Displays a progress bar during file upload/download FUNCTION FtpProgress( nSent, nTotal, oFtp ) LOCAL cProgress LOCAL nRow := Row(), nCol := Col() cProgress := Replicate( Chr(178), Int( MaxCol()*nSent/nTotal ) ) SetPos( MaxRow()-1, 0 ) ?? oFtp:oUrl:cFile ? PadR( cProgress, MaxCol() ) SetPos( nRow, nCol ) RETURN .T.
http://www.xHarbour.com