Page 1 of 1

How to access FTP read-only?

Posted: Thu Nov 21, 2013 7:20 pm
by Matheusfarias
Hello guys, I'm using the classes of xHarbour to manage the movements of my FTP programa.I Have a client that uses a third party service (FTP) access ,is read-only and class access is Read and Write (:: nAccessMode: = TIP_RW / / a read-write protocol), I tried to modify all forms, could not, anyone have any idea?Follows the part of the Code:

Code: Select all


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


 

Re: How to access FTP read-only?

Posted: Fri Nov 22, 2013 1:11 am
by ADutheil
Did you try this:

Code: Select all

   oFTP              := tIPClientFtp():New( oUrl, file("c:\desenv.sys") )
   oFTP:nConnTimeout := 20000
   oFTP:bUsePasv     := .T.
   oFTP:nAccessMode  := TIP_RO // #define TIP_RO 0

 

Re: How to access FTP read-only?

Posted: Fri Nov 22, 2013 12:17 pm
by Matheusfarias
ADutheil friend, not only that but tried several options how to manipulate the functions of the class dates yet unsuccessfully, to already put the class in the project build but still the changed value did not work.
Note: the value of DATA is changed but I can not access.

Re: How to access FTP read-only?

Posted: Fri Nov 22, 2013 8:00 pm
by Matheusfarias
Hi all, I solved the problem by passing the instaciado parameter instead of cUrl object. Tip is. :D

Code: Select all

   cUrl      := "ftp://" + cUser + ":" + cPassword + "@" + cServer
   oUrl              := tUrl():New( cUrl )
   oFTP              := tIPClientFtp():New( oUrl, file("c:\desenv.sys") )
   oFTP:nDefaultPort := 21
   oFTP:nConnTimeout := 3000
   oFTP:bUsePasv     := .T.

   if At("@",cUrl)>0
      oFTP:oUrl:cServer   := cServer
      oFTP:oUrl:cUserID   := cUser
      oFTP:oUrl:cPassword := cPassword
   endif

   IF oFTP:Open( oFTP:oUrl )
      oFTP:oUrl:cPath := cRemoteDir
      IF !oFtp:DownloadFile( cLocalFile,cRemoteFile )
         lRetorno := .F.
      ELSE
         lRetorno := .t.
      ENDIF
      oFTP:Close()
  Endif