[Gambas-user] About FTP Client
Caveat
Gambas at ...1950...
Fri Feb 26 13:22:09 CET 2010
Hi Tobi
I hope you don't mind me including the Gambas mailing list in my reply,
as this information may be of interest to others on the list too.
Question 1, part 1:
This is quite simple once you understand that files and directories are
kind of the same thing when it comes to FTP.
So, for example, with some very simple code based on the examples I sent
Lars, you can get a local file in text form which is a directory
listing. Try pointing getFileByFTP (in my RequestManager class) at a
directory instead of a regular file. For this example I'm connecting to
a DreamBox satellite receiver, which is a Linux-based machine.
So in getFileByFTP, I set the url to just the ip address of the
DreamBox, the userid and password to the appropriate values and the
local file to /tmp/gambas.txt.
After running it, we find the following content in /tmp/gambas.txt:
drwxr-xr-x 2 0 0 0 Jan 01 2000 autofs
drwxrwxr-x 3 0 0 0 Jan 01 1970 bin
drwxr-xr-x 3 0 0 0 Jan 01 1970 boot
drwxr-xr-x 1 0 0 0 Jan 01 1970 dev
drwxr-xr-x 30 0 0 0 Jan 01 2000 etc
lrwxrwxrwx 1 0 0 9 Jan 01 1970 hdd -> media/hdd
drwxrwxr-x 3 0 0 0 Jan 01 1970 home
drwxrwxr-x 4 0 0 0 Jan 01 1970 lib
drwxrwxr-x 12 0 0 0 Apr 25 2008 media
lrwxrwxrwx 1 0 0 5 Jan 01 1970 mnt -> media
dr-xr-xr-x 77 0 0 0 Jan 01 2000 proc
drwxrwxr-x 3 0 0 0 Jan 01 1970 sbin
lrwxrwxrwx 1 0 0 10 Jan 01 1970 share
-> /usr/share
drwxr-xr-x 9 0 0 0 Jan 01 2000 sys
drwxrwxrwt 3 0 0 220 Feb 26 06:59 tmp
drwxr-xr-x 17 0 0 0 Feb 22 2009 usr
drwxr-xr-x 10 1000 100 440 Jan 01 2000 var
I wouldn't think that this would be too hard to write a parser for. Let
me know if you get stuck on this. I'd also suggest you look at the
Gambas TreeView component as it may work well for drilling down into
directories etc.
Now let's imagine you have written a parser/gui, and the user has
selected the 'var' directory to see what's in there. Simply point your
url to the ip address of the machine with /var/ added to the end (NB:
the final / is important!). So your url might be something like the
string "192.168.1.15/var/". Obviously, to drill down further into the
directory structure, you just keep adding the directory names... so
192.168.1.15/var/log/ might return something like:
drwx------ 4 0 0 80 Jan 01 2000 cores
-rw-r--r-- 1 1000 100 0 Jan 01 2000 lastlog
-rw-r--r-- 1 0 0 1169 Jan 28 08:07 log.nmbd
-rw-r--r-- 1 0 0 750 Jan 01 2000 log.smbd
-rw------- 1 0 0 611 Feb 26 11:12 vsftpd.log
-rw-r--r-- 1 1000 100 2304 Jan 01 2000 wtmp
Here you can see that you can drill down further into the cores
directory, or you have regular files that you can download... like
lastlog or wtmp for example (just remember not to add the final "/" for
regular files). I hope you already spotted the little clue... directory
lines start with a 'd' and lines for regular files start with a '-',
link lines start with an 'l'... already you have the beginnings of your
logic to parse this...
Question 1, part 2:
Some of this is simple enough, FTPClient in Gambas supports for sure get
and put so getting files off the FTP server and putting them up there
shouldn't be a problem. Whether you can rename/delete files on the
server using Gambas FTPClient is something I'm not sure about.
Question 2:
See the comments on Question 1, part 1.
Question 3:
Sure! :-)
Regards,
Caveat
P.S. Here's the code from the Form I made to test this out:
' Gambas class file
PRIVATE rManager AS RequestManager
PUBLIC SUB _new()
END
PUBLIC SUB Form_Open()
rManager = NEW RequestManager
END
PUBLIC SUB Button1_Click()
rManager.getFileByFTP(urlTxt.Text, useridTxt.Text, passwordTxt.Text,
"/tmp/gambas.txt")
END
On Wed, 2010-02-24 at 19:55 +0100, tobiasboe at ...221... wrote:
> Hello Caveat,
>
> with a big interest I read your posting refered to the FTP-Client in
> disputation with Lars. I have the following questions about that:
>
> (1) How can I look up the structure of a directory on the FTP server I
> am connected with. That's necessary to copy files from the server to
> my pc (download), to delete or rename any file or copy a file to the
> server (upload).
>
> (2) How could I display this structure of a directory?
>
> (3) I would like to use the code in your reply in my own code, is that
> OK?
>
> Please excuse my english, I am German.
>
> Regards,
> Tobi
More information about the User
mailing list