Código: Selecionar todos
#include "fileio.ch"
#include "common.ch"
#include "Directry.ch"
FUNCTION UP(cArquivo,cPasta,cFtpServer,nPorta,cUsuario,cPass,bIdentico,cCaminhoArquivo)
Local cUrl, oUrl, oFTP, aFile, aArquivo, aArqAux := {}, nCont := 1, aErro := {}
if bIdentico == nil; bIdentico := .t.; endif
if cCaminhoArquivo == nil; cCaminhoArquivo := ""; endif
//IF oFTP:DELE('/'+FTPDIR+'/'+ARQFTP) ; EXIT ; ELSE ; LOOP ; ENDIF
if Valtype(cArquivo) == "A"
for nCont = 1 to len(cArquivo)
cArquivo[nCont] := alltrim(cArquivo[nCont])
if File(cCaminhoArquivo+cArquivo[nCont])
aadd(aArqAux, cArquivo[nCont])
endif
next
elseif Valtype(cArquivo) == "C"
cArquivo := alltrim(cArquivo)
aadd(aArqAux, cArquivo)
if File(cCaminhoArquivo+aArqAux[nCont])
aadd(aArqAux, cArquivo)
endif
else
mouse(.f.)
@ 23,00 say padc("Arquivo nao e char e nem array",80)
inkey(5)
return .f.
endif
if len(aArqAux) <= 0
mouse(.f.)
@ 23,00 say padc("Nao encontrou o Arquivo!! ",80)
inkey(5)
mouse(.t.)
return .f.
endif
cPasta := alltrim(cPasta)
cUrl := "ftp://" + cUsuario + ":" + cPass + "@" + cFtpServer
oUrl := TUrl():New( cUrl )
oFTP := TIPClientFtp():New( oUrl, .T. )
oFTP:nConnTimeout := 20000
oFTP:bUsePasv := .T. // F = ENVIA BINARIO E FICA ZERO BYTE
oFTP:nDefaultPort := nPorta //PORTA DO FTP
oFTP:oUrl:cUserID := cUsuario
oFTP:oUrl:cServer := cFtpServer
oFTP:oUrl:cPassword := cPass
@ 23,00 say padc("Abrindo conex„o com o FTP.....Aguarde!!!",80)
IF oFTP:Open( cUrl )
IF !oFTP:Cwd(cPasta) // se não achar o diretorio ele cria
mouse(.f.)
@ 23,00 say padc("Criando pasta ("+cPasta+")",80)
inkey(5)
mouse(.t.)
oFTP:Mkd(cPasta) // cria o diretorio
ENDIF
oFTP:Cwd(cPasta) // informe o diretorio (no servidor ftp) onde está o arquivo versao.txt
If !empty(oFTP:List()) .and. Len(aArqAux) > 0 .and. !empty(aArqAux[1])&& verificar c nao sao identicos
for nCont = 1 to len(aArqAux)
cArquivo := aArqAux[nCont]
aArquivo := oFTP:ListFiles(cArquivo)
aFile := directory(cCaminhoArquivo+cArquivo)
if Len(aFile) # 0 .and. Len(aArquivo) # 0&& verificar c arquivo ja foi baixado
if aArquivo[1,2] == aFile[1,2] .and. bIdentico == .t.
mouse(.f.)
@ 23,00 say padc("Arquivo identico!!!",cPasta+cArquivo,80)
inkey(5)
mouse(.t.)
nCont++
loop
endif
endif
nTAMANHO := 0
aDir0 := directory(cCaminhoArquivo+cArquivo)
nTAMANHO := aDir0[1,2]
oFtp:exGauge := {|nPronto| FtpProgress(nPronto,nTamanho) }
if oFtp:UploadFile( cCaminhoArquivo+cArquivo, cPasta + '/' + cArquivo ) = .f.
mouse(.f.)
@ 23,00 say padc("N„o é possivel enviar o arquivo ("+cCaminhoArquivo+cArquivo+")",80)
aadd(aErro, "N„o é possivel enviar o arquivo ("+cCaminhoArquivo+cArquivo+")")
inkey(5)
mouse(.t.)
endif
next
endif
oFTP:CWD( ".." )
Millisec(1000)
oFTP:Close()
if Len(aErro) > 0
Return .f.
endif
ELSE
Return .f.
ENDIF
RETURN .T.
// =============================================================================
Function Do(cArquivo,cPasta,cFtpServer,nPorta,cUsuario,cPass,cPastaDownload,bIdentico) // Realiza download de atualização via ftp
Local cUrl, oUrl, oFTP, oCred, cList, bRet, aArquivo, nTamanho , aFile
if cPastaDownload == nil; cPastaDownload := CLTEMP; endif
if bIdentico == nil; bIdentico := .t.; endif
cUrl:="ftp://"+cUsuario+":"+cPass+"@"+cftpserver // url ftp
oUrl:= turl():new(curl)
oCred:= tIPCredentials()
oFtp:= tipclientftp():NEW(oUrl,,.T.)
oFTP:nConnTimeout := 20000
oFTP:bUsePasv := .T.
@ 23,00 say padc("Abrindo conexao com o FTP.....Aguarde!!!",80)
If oFTP:Open() // Abre conexão ftp
oFTP:Cwd(cPasta) // informe o diretorio (no servidor ftp) onde está o arquivo versao.txt
If !empty(oFTP:List())
aArquivo := oFTP:ListFiles(cArquivo)
if Len(aArquivo) == 0
oFTP:Close() // -> encerra conexão com servidor ftp
mouse(.f.)
@ 23,00 say padc("Error não localizou arquivo!",cPasta+cArquivo,80)
inkey(5)
mouse(.t.)
return .f.
endif
aFile := directory(cPastaDownload+cArquivo)
if Len(aFile) # 0 .and. Len(aArquivo) # 0&& verificar c arquivo ja foi baixado
if aArquivo[1,2] == aFile[1,2] .and. bIdentico == .t.
oFTP:Close() // -> encerra conexão com servidor ftp
mouse(.f.)
@ 23,00 say padc("Arquivo identico!!!",cPasta+cArquivo,80)
inkey(5)
mouse(.t.)
return .t.
endif
endif
ApagaArq(cPastaDownload+cArquivo)
nTamanho := aArquivo[1,2]
oFtp:exGauge := {|nPronto| FtpProgress(nPronto,nTamanho) }
bRet := oFtp:DownLoadFile(cPastaDownload+cArquivo,cPasta+cArquivo) // baixa o arquivo versão.txt existente na pasta update no servidor ftp
If !file(cPastaDownload+cArquivo) // se exister o arquivo,
oFTP:Close() // -> encerra conexão com servidor ftp
mouse(.f.)
@ 23,00 say padc("Erro: Arquivo "+cPasta+cArquivo+" não encontrado!",80)
inkey(5)
mouse(.t.)
return .f.
EndIf
oFTP:Close() // -> encerra conexão com servidor ftp
EndIf
Else
mouse(.f.)
@ 23,00 say padc("Error ao tentar conectar no servidor de atualização, por favor verifique sua conexção com a internet!",80)
inkey(5)
mouse(.t.)
return .f.
EndIf
Return .t.
//******************************************************
FUNCTION FtpProgress( nSent, nTotal, oFtp )
LOCAL cProgress
LOCAL nRow := 23, nCol := 00
cProgress:= STR((nSent/nTotal)*100,4)+"%"
@ nRow, nCol say padc("Comunicando..." + cProgress,80)
SetPos( MaxRow()-1, 0 )
SetPos( nRow, nCol )
RETURN .T.
//**********************************************
essa função esta no forum, só não lembro onde peguei!! mas esta ai, mastigadinho!!!