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

Phan Damily phandamily at yahoo.com
Sun Feb 18 08:16:57 CET 2018


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.


 

    On Wednesday, February 14, 2018, 1:52:06 PM EST, T Lee Davidson <t.lee.davidson at gmail.com> wrote:  
 
 

On 02/14/2018 01:18 PM, Phan Damily via User wrote:
> I've been teaching myself FTPCLIENT.
> 
> What I'm trying to do is to modify a file on a remote server "on the fly", as quickly as possible, using FTP. I'm able to read
> the remote file into a String variable in Gambas using FTP.Then, I modify the String variable in whatever way needed using
> Gambas string functions. Once that's done, what I'm trying to do is write the data from that String variable to the remote file
> via FTP, overwriting all its contents with the modified data from the String variable.
> 
> From the code examples I'm finding in searches (most are 10 years old, or older), the only way it seems possible to do this is
> to first write the data from the String variable to a local file first. And then send that local file to the remote server via
> FTP, overwriting the original file, using FTPCLIENT's Put method.
> 
> I can do that. But it seems like unnecessary overhead and unnecessary extra steps, if the modification can be done directly from
> the String variable.
> 
> Is there a newer method in Gambas 3.10.0 that wasn't available 10 years ago that allows this to be done? Or is it a limitation
> of the FTP protocol? Is there a way to trick Gambas into thinking a String variable is a file? Is there some other protocol
> Gambas supports that would be more suited to directly modifying remote files without the overhead of using temp files?
> 
> Thanks for reading.

The FtpClient methods are listed at: http://gambaswiki.org/wiki/comp/gb.net.curl/ftpclient

There is no method to store a string as a file. There is, however, the Exec method which would allow you to execute the FTP
'STOR' command. See: https://en.wikipedia.org/wiki/List_of_FTP_commands

Doing that sounds like extra steps as well.

I think the quickest way to implement a solution is to simply use temp files. Unless you have huge files and/or hundreds of
them, the overhead should not be significant.


-- 
Lee

--------------------------------------------------

This is the Gambas Mailing List:
https://lists.gambas-basic.org/listinfo/user

Search the list:
https://lists.gambas-basic.org/cgi-bin/search.cgi

Hosted by https://www.hostsharing.net
  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180218/f34f71ad/attachment-0001.html>


More information about the User mailing list