Quis dizer que ele vai até o fim da função sem dar erro, ou seja, a função oFtp:DownLoadFile(arqvpeg) retorna .t., como se o arquivo tivesse sido baixado.
O arquivo não foi baixado, pois ele não se encontra no disco local.
O nome do arquivo a ser baixado está no conteúdo da variável arqvpeg.
Como assim salvar o download? Ao baixar, ele já não salva automaticamente no disco?
Eu tenho uma outra função muito semelhante a esta, que funciona perfeitamente. A única diferença é que esta outra apaga o arquivo do FTP, coisa que esta não faz. Veja:
Código: Selecionar todos
Function recebftp(arqvrec,pasta)
ftpproto ="ftp://" //posthilit">ftp://"
ftpserver = ftps //posthilit">ftp.servidor.com.br" endereço de ="posthilit">FTP</span> do site
ftpuser = usftp //Usuário da conta ="posthilit">FTP</span>
ftppass = snhftp //Senha da conta ="posthilit">FTP</span>
curl:=ftpproto+ftpuser+":"+ftppass+"@"+ftpserver
oUrl:= turl():new(curl)
oCred:= tIPCredentials()
oFtp:= tipclientftp():NEW(oUrl,,.T.)
oFTP:nConnTimeout := 20000
oFTP:bUsePasv := .T.
pasta=alltrim(pasta)
nTentativa=0
do while .t.
IF oFTP:Open()=.t.
exit
else
@ maxrow()-1,1 clear to maxrow()-1,maxcol()-1
@ maxrow()-1,1 say "Não abriu o FTP; tentando novamente ("+alltrim(str(nTentativa))+")"
nTentativa++
inkey(5)
if nTentativa>8
erecftp="nao conectou"
return .f.
endif
endif
enddo
nTentativa=0
do while .t.
oFTP:Cwd( "" )
if oFTP:Cwd(pasta)=.t. // informe o diretorio (="posthilit">no</span> site) onde está o arquivo EXE que voce vai copiar
exit
else
@ maxrow()-1,1 clear to maxrow()-1,maxcol()-1
@ maxrow()-1,1 say "Não abriu a pasta no FTP; tentando novamente ("+alltrim(str(nTentativa))+")"
nTentativa++
inkey(3)
if nTentativa>7
erecftp="pasta "+pasta+" não foi aberta"
return .f.
endif
endif
enddo
nTentativa=0
do while .t.
if oFtp:DownLoadFile(arqvrec)=.t. //informe o nome do arquivo que você quer baixar
exit
else
if "atemp"$arqvrec
return .t.
endif
@ maxrow()-1,1 clear to maxrow()-1,maxcol()-1
@ maxrow()-1,1 say "Não recebeu o arquivo "+arqvrec+"; tentando baixar novamente"
nTentativa++
inkey(5)
sele 4
if conexsql()
DBUSEAREA( .T.,, "SELECT * FROM tarefas WHERE usuario='"+us+"'", "recebftp")
locate for data=date() .and. val(substr(hora,1,2))=val(substr(time(),1,2)) .and. acao="Recebim" .and. nrtarefa=arqvrec
if found()
return .t.
endif
endif
use
sele 1
if us="I" .and. nTentativa>2
tone(261.7,nTentativa)
endif
if nTentativa>8
erecftp="não recebeu arquivo"
return .f.
endif
endif
enddo
nTentativa=0
do while .t.
if oFtp:DELE(arqvrec)=.t.
exit
else
@ maxrow()-1,1 clear to maxrow()-1,maxcol()-1
@ maxrow()-1,1 say "Não apagou o arquivo "+arqvrec+" do FTP; tentando novamente ("+alltrim(str(nTentativa))+")"
nTentativa++
inkey(3)
if nTentativa>7
erase exclui.log
if verarqv("exclui.bat")=.t.
__run("exclui " + ftps + " " + usftp + " " + snhftp + " " + pasta + " . " + arqvrec)
cexcl:=ALLTRIM(MEMOREAD("C:\tarefas\exclui.log"))
if at("DELE command successful",cexcl)=0
if us="I"
?"Erro COMUNS 385 - não apaga o arquivo recebido"
tone(261.7,33)
inkey(10)
else
if mandmail1("copp.txt","Não conseguiu excluir arquivo "+arqvrec+ " (COMUNS 386)")=.f.
?"Avisar ao Dr. Inacio que não está apagando o arquivo do FTP"
tone(261.7,33)
endif
endif
endif
else
mandmail1("","Não tem o arquivo exclui.bat")
endif
exit
endif
endif
enddo
oFTP:Close()
Return .t.