Funzionamento tIpClientFtp

Moderator: Enrico Maria Giordano

Funzionamento tIpClientFtp

Postby Marco Turco » Sun May 03, 2009 8:10 am

Salve,
vorrei provare la class tIpClientFtp per effettuare upload/download da un server ftp ma la documentazione è piuttosto scarna.
avete per caso un esempio di questa classe ?

Io sul sito xharbour.com ho trovato questo esempio ma nel mio caso devo autenticarmi con userid e password sul server ftp
e non ho capito se prima devo utilizzare la classe tIpClient per attivare la connessione.

Qualche idea ?

Grazie

**********

#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.
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Return to All products support

Who is online

Users browsing this forum: No registered users and 9 guests