Baseado em exemplos do forum montei esta rotina para importa e exporta arquivos via FTP.
Minha duvida:
Como faço para baixar todos os arquivos de uma pasta FTP, sem saber o nome dos arquivos que por ventura estejam nela.
Desta maneira que esta abaixo, consigo enviar e receber os arquivos que SEI o nome, o que preciso e pegar arquivos de uma pasta sem saber os nomes que podem variar.
Ja tentei, como oFTP:LIST(), oFTP:LISTFILES(), mais sem sucesso.
Os dois metodos retornam:
20141029-20:57:41 :INETRECVALL( 2B30544, , 512 )
>> 10-29-14 04:49PM 21 TesteFtp.txt
10-29-14 04:49PM 21 TesteFtp01.txt
mais não copiam o arquivo.
Ja tentei tratar mais não consegui fazer o download deles.
Se alguém pudesse corrigir esta rotina...
Código: Selecionar todos
FUNCTION TESTA_DOWN()
clear
ALERTPRETO([Voce deseja],{[ Enviar ],[ Receber ]},1)
IF nOPT = 1
Upload_FTP([TesteFPT.txt] )
ELSE
DownLoad_FTP()
ENDIF
CLEAR
RETURN NIL
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *>
function DownLoad_FTP()
LOCAL lRetVal := .T.
LOCAL aFiles, cFile
LOCAL oFTP, oURL, cFILESPEC
IF ! Empty( aFiles := { [TesteFtp.txt],[TesteFtp01.txt] } )
cServer := "192.168.1.132"
cUser := "Gilberto64"
cPassword := "cla"
cUrl := "ftp://" + cUser + ":" + cPassword + "@" + cServer
oURL := TUrl():New( cURL )
oFTP := TIPClientFTP():New( oURL, .T. )
oFTP:nConnTimeout := 20000
oFTP:bUsePasv := .T.
IF oFTP:Open( cURL )
FOR EACH cFile IN aFiles
? "Filename:", cFile
IF oFtp:DownloadFile( cFile )
//oFtp:Dele( cFILE )
lRetVal := .T.
ELSE
lRetVal := .F.
EXIT
ENDIF
NEXT
oFTP:Close()
ELSE
? "Could not connect to FTP server", oURL:cServer
IF oFTP:SocketCon == NIL
? "Connection not initialized"
ELSEIF inetErrorCode( oFTP:SocketCon ) == 0
? "Server response:", oFTP:cReply
ELSE
? "Error in connection:", inetErrorDesc( oFTP:SocketCon )
ENDIF
lRetVal := .F.
ENDIF
// ENDIF
ErrorLevel( iif( lRetVal, 0, 1 ) )
RETURN
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *>
FUNCTION Upload_FTP( )
LOCAL aFiles, cFile
LOCAL oFTP, oURL
/* fetch files to transfer */
IF !Empty( aFiles := { [TesteFtp.txt] } )
cServer := "192.168.1.132"
cUser := "Gilberto64"
cPassword := "cla"
cUrl := "ftp://" + cUser + ":" + cPassword + "@" + cServer
oURL := TUrl():New( cURL )
oFTP := TIPClientFTP():New( oURL, .T. )
oFTP:nConnTimeout := 20000
oFTP:bUsePasv := .T.
IF oFTP:Open( cURL )
FOR EACH cFile IN aFiles
? "Filename:", cFile
IF !oFtp:UploadFile( cFile )
lRetVal := .F.
EXIT
ELSE
lRetVal := .T.
ENDIF
NEXT
oFTP:Close()
ELSE
? "Could not connect to FTP server", oURL:cServer
IF oFTP:SocketCon == NIL
? "Connection not initialized"
ELSEIF inetErrorCode( oFTP:SocketCon ) == 0
? "Server response:", oFTP:cReply
ELSE
? "Error in connection:", inetErrorDesc( oFTP:SocketCon )
ENDIF
lRetVal := .F.
ENDIF
ENDIF
ErrorLevel( iif( lRetVal, 0, 1 ) )
RETURN
