Code: Select all | Expand
Function FtpDownload(cServer,cUser,cPassword,cRemoteFile,cLocalFile,cRemoteDir) Local oUrl , cUrl , oFtp , cStr , lRetorno Default cServer:="",cUser:="",cPassword:="",cRemoteFile:="",cRemoteDir:="" if Empty(cServer) msgAlert("Atenção Host não informado!","Alerta") return .f. endif if Empty(cUser) msgAlert("Atenção Usuario não informado!","Alerta") return .f. endif if Empty(cPassword) msgAlert("Atenção Senha não informado!","Alerta") return .f. endif if Empty(cRemoteFile) msgAlert("Atenção Arquivo não informado!","Alerta") return .f. endif if !isConnected() msgAlert("Atenção Sem Conexão com a Internet!","Alerta") return .f. endif cUrl := "ftp://" + cUser + ":" + cPassword + "@" + cServer oUrl := tUrl():New( cUrl ) oFTP := tIPClientFtp():New( oUrl, file("c:\desenv.sys") ) oFTP:nConnTimeout := 20000 oFTP:bUsePasv := .T. IF At( "@", cUser ) > 0 oFTP:oUrl:cServer := cServer oFTP:oUrl:cUserID := cUser oFTP:oUrl:cPassword := cPassword ENDIF IF oFTP:Open( cUrl ) oFTP:oUrl:cPath := cRemoteDir IF !oFtp:DownloadFile( cLocalFile+cRemoteFile,cRemoteFile ) lRetorno := .F. ELSE lRetorno := .t. ENDIF oFTP:Close() ELSE cStr := "Não foi possivel conectar ao Ftp:" + oURL:cServer IF oFTP:SocketCon == NIL cStr += Chr( 13 ) + Chr( 10 ) + "Conexão não iniciada!" ELSEIF InetErrorCode( oFTP:SocketCon ) == 0 cStr += Chr( 13 ) + Chr( 10 ) + "Resposta do Servidor:" + " " + oFTP:cReply ELSE cStr += Chr( 13 ) + Chr( 10 ) + "Erro na Conexão:" + " " + InetErrorDesc( oFTP:SocketCon ) ENDIF msgstop(cStr,"Erro") lRetorno:=.f. ENDIF RETURN lRetorno