[Gambas-user] Can Gambas write directly from a String variable to a remote file via FTP?

Tobias Boege taboege at gmail.com
Sun Feb 18 20:11:49 CET 2018


On Sun, 18 Feb 2018, Benoît Minisini wrote:
> Le 18/02/2018 à 08:16, Phan Damily via User a écrit :
> > Thank you for the reply, Lee. Yes, ultimately my project will be
> > modifying hundreds of small files at a time, and sending to a remote
> > server.
> > 
> > I'm sorry to learn that there's not a way to avoid extra steps,
> > regardless of the method used. I've decided on having my Gambas project
> > create/mount a ram disk on Form_Open, write the modified String data to
> > a temp file on the ram disk, upload the temp file using the Put command,
> > and unmount the ram disk when I click the Exit button.
> > 
> > The upload of one tiny text file works flawlessly in tests, and seems
> > instantaneous. However, hundreds of files may be a different matter, as
> > I think FTP must close the connection and open a new one with each file
> > transfer (unless I'm mistaken). I'll look into sFTP, which my
> > understanding is it re-uses the same connection. This allows uploads to
> > be back-to-back, for much less overhead. I'm not sure if Gambas natively
> > supports sFTP but I'm looking into it.
> > 
> > Thanks again.
> > 
> No, you can keep the same FtpClient connection to send multiple files.
> 
> But be prepare: sometimes the FtpClient will return an error (FTP servers
> seem to have some sort of timeouts), and you have to reconnect to continue
> sending your files.
> 

Looking at the source code, it should be easy to add sending file content
from a String as well. All you need to give to curl is a callback that
provides it with new data to transfer. This is precisely what the Stream
class provides and Gambas has String streams in particular. But what should
the new method be called?

A signature of Put(hStream As Stream) would have been a better fit for
the capabilities of curl. Either that or using the FtpClient (Inherits Curl
Inherits Stream) itself as a buffer, so that you can initiate a STOR
command and then "Write #hFtpClient, Data". What do you think?

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk


More information about the User mailing list