Send file using TipClientFTP()

181 views
Skip to first unread message

Daniel Du Pré

unread,
Aug 4, 2023, 9:50:52 AM8/4/23
to Harbour Users
Hola a todos.
Estoy intentando enviar archivos usando TipClientFTP() pero no lo logro.
He visto varios hilos en el foro que hablan del problema que existe cuando el usuario o las contraseña incluyen "@".
Esto es lo que estoy intentando pero no anda y por más que busco no encuentro la solución.
¿alguien podría indicarme que estoy haciendo mal?
Muchas gracias.

FUNCTION EnvioFtp(cArchivo)
local cUrl, lRetval
local oFtp, oUrl
local cServer, cUser, cPass,

lRetval := .T.

cServer := "ftp://miservidor.com"
cUser   := "dan...@miservidor.com"
cPass   := "Clave$del!servidor"

oUrl  := TUrl():New()
oUrl:cAddress   :=  "ftp://miservidor.com"
oUrl:cServer    := " miservidor.com"
oUrl:cUserID    := cUser
oUrl:cPassword  := cPass
oUrl:cProto     := "ftp"
oUrl:nPort      := 21

oFtp := TIPClientFTP():New( oUrl, .T.)
oFtp:nConnTimeout := 20000
oFtp:bUsePasv := .T.

if oFtp:Open( cServer )        <============ aquí no entra y se va por el else
   if ! oFtp:UploadFile(cArchivo)
      lRetval := .F.
   else
      oFtp:Close()
   endif
else
   ? "No se puede conectar al servdor FTP ", oUrl:cServer
   if oFtp:SocketCon == NIL
      ? "Conexion no inicializada"
   elseif hb_inetErrorCode( oFtp:SocketCon ) == 0
      ? "El servidor respondio:", oFtp:cReply
   else
      ? "Error in conexion:", hb_inetErrorDesc( oFtp:SocketCon )
   endif
   lRetval := .F.
endif

return lRetval

Klas Engwall

unread,
Aug 4, 2023, 10:54:48 AM8/4/23
to harbou...@googlegroups.com
Hi Daniel,

This does not look like it is the same problem that has been discussed
many times here, where server+user+password is sent to the tUrl class as
one single string and the tUrl class is unable to correctly separate the
different parts of the string.

You are doing exactly what has been suggested here before to solve that
common tUrl problem, so tUrl should know exactly what is what in your
case. I believe the problem must be searched elsewhere.

A good place to start the analysis is to study the log file. You call
the TIPClientFtp() class with <xTrace> set to .T., so a log file should
have been created. Can you post it for is to see?

Regards,
Klas
> --
> You received this message because you are subscribed to the Google
> Groups "Harbour Users" group.
> Unsubscribe: harbour-user...@googlegroups.com
> Web: https://groups.google.com/group/harbour-users
> <https://groups.google.com/group/harbour-users>
> ---
> You received this message because you are subscribed to the Google
> Groups "Harbour Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to harbour-user...@googlegroups.com
> <mailto:harbour-user...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/harbour-users/60141363-0979-46f7-b050-13416ade763fn%40googlegroups.com <https://groups.google.com/d/msgid/harbour-users/60141363-0979-46f7-b050-13416ade763fn%40googlegroups.com?utm_medium=email&utm_source=footer>.
Message has been deleted

Hurricane

unread,
Aug 4, 2023, 11:12:24 PM8/4/23
to Harbour Users
Hi Daniel,

In the Articles, Samples, Tips section (send file via FTP), I posted a complete and summarized example (which I use in developments).

For any type of integration (SQL, FTP, SITE...), I always suggest starting with a client, utility, checking credentials, functioning, etc... only then using the programming code (learning a new resource).

Note: it's for your console application, correct? because in its GUI tool it has its own class.

Regards,
Hurricane
Software developer
Training, general development

Daniel Du Pré

unread,
Aug 5, 2023, 9:52:15 AM8/5/23
to Harbour Users
Klas,
Muchas gracias por responder.
No se porqué pero lamentablemente no se crea el ftp.log .

Saludos
Daniel

Google traslator
Klas, Thank you very much for answering.
I don't know why but unfortunately the ftp.log is not created.
Greetings
Daniel

Daniel Du Pré

unread,
Aug 5, 2023, 10:46:13 AM8/5/23
to Harbour Users
Hola Eric,
Muchas gracias por responder.
Voy a estudiar el artículo que me envías.
He hecho pruebas enviando y recibiendo con FileZilla sin problema.
El espacio que aparece en el nombre del servidor fue un error mío al escribir el mensaje, en el archivo fuente está sin espacio en blanco.

Nota: Con mi herramienta GUI ya lo he probado y funciona muy bien, pero ahora tengo la necesidad de incorporar esta opción a mi aplicación consola.
Saludos
Daniel

Google traslator
Hi Eric,
Thank you very much for answering.
I will study the article you sent me.
I have done tests sending and receiving with FileZilla without problem.
The space that appears in the name of the server was my mistake when writing the message, in the source file there is no white space.

Note: With my GUI tool I have already tested it and it works very well, but now I need to add this option to my console application.

Regards,
Daniel

Daniel Du Pré

unread,
Aug 5, 2023, 11:10:12 AM8/5/23
to Harbour Users
Problema resuelto.
el error estaba en la forma de escribir el nombre del servidor:
yo ponía          cServer := "ftp://miservidor.com"
y debí poner   cServer := "ftp.miservidor.com"

Gracias a todos por la ayuda.
Saludos
Daniel

Google traslator

Problem solved.
The error was in the way of writing the name of the server:
I put                                cServer := "ftp://myserver.com"
and I should have put  cServer := "ftp.myserver.com"

Thanks to all for the help.

Regards
Daniel

Klas Engwall

unread,
Aug 5, 2023, 1:19:07 PM8/5/23
to harbou...@googlegroups.com
Hi Daniel,

> Problema resuelto.

Good!

> el error estaba en la forma de escribir el nombre del servidor:
> yo ponía cServer := "ftp://miservidor.com"
> y debí poner cServer := "ftp.miservidor.com"

I suppose one sees what one expects to se, so before Hurricane jumped in
I had read it as "ftp.miservidor.com" :-)

Before we close this, let me suggest a couple of other things:

// cServer := "ftp.miservidor.com" // Skip this
cUser := "dan...@miservidor.com"
cPass := "Clave$del!servidor"

oUrl := TUrl():New()
// oUrl:cAddress := "ftp.miservidor.com" // Skip this
oUrl:cServer := "ftp.miservidor.com"
oUrl:cUserID := cUser
oUrl:cPassword := cPass
oUrl:cProto := "ftp"
oUrl:nPort := 21

oFtp := TIPClientFTP():New( oUrl, .T. )
oFtp:nConnTimeout := 20000
oFtp:bUsePasv := .T.

if oFtp:Open() // Skip the argument, tUrl has it already

... and so on

When using oUrl:cAddress the tUrl class will want to split the cAddress
string into oUrl:cServer, oUrl:cUserID and oUrl:cPassword. But you
already provide those one by one, which is much safer given that the
parser in tUrl is not entirely adequate.

The same thing will happen again if you provide cServer with your
oFtp:Open() call. But the tUrl class already knows which server to open,
so leave oFtp:Open() with no arguments.

Regards,
Klas

Daniel Du Pré

unread,
Aug 5, 2023, 4:49:01 PM8/5/23
to Harbour Users
Klas
Excelente explicación.
Nuevamente muchas gracias

Saludos
Daniel

Google traslator
Klas
Excellent explanation.
Again thank you very much

Regards
Daniel
Reply all
Reply to author
Forward
0 new messages