How to get a filelist of an ftp server?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 76
- Joined: Sat Nov 07, 2009 7:43 pm
How to get a filelist of an ftp server?
Hi everybody,
I would like to know how I can get a list of the files in a directory on a FTP Server, display this list in a Field and provide the user the ability to select the file and download it.
I know how to connect to the FTP server but I fail in getting the list and processing it so when the User selects the displayed Filename and he hits the downloadbutton the DownloadURL of the displayed file should be processed.
Help would be appreciated,
Masterchief
I would like to know how I can get a list of the files in a directory on a FTP Server, display this list in a Field and provide the user the ability to select the file and download it.
I know how to connect to the FTP server but I fail in getting the list and processing it so when the User selects the displayed Filename and he hits the downloadbutton the DownloadURL of the displayed file should be processed.
Help would be appreciated,
Masterchief
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: How to get a filelist of an ftp server?
This works well here for getting the list (note the trailing slash, needed to distinguish from a file request:
put url "ftp://user:pass@domain.com/folder/" into fld "MyField"
put url "ftp://user:pass@domain.com/folder/" into fld "MyField"
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
Re: How to get a filelist of an ftp server?
Depending on the FTP server, you may have to use libURLSetFTPListCommand first to toggle between "LIST" and "NLST" in order to obtain a readable list.
HTH,
Jan Schenkel.
HTH,
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com
-
- Posts: 76
- Joined: Sat Nov 07, 2009 7:43 pm
Re: How to get a filelist of an ftp server?
Thank you. Is working but the only message I get in my Field is: "error invalid host adress"
Can´t find the actuall error because I set up a FTP Server on my localhost with the login data
Login: root
pass: xxxx
Do you know why this happens?
Can´t find the actuall error because I set up a FTP Server on my localhost with the login data
Login: root
pass: xxxx
Code: Select all
on mouseUp
libURLSetFTPListCommand "NLST"
open URL "ftp://root:xxxx@localhost/" -- Open the FTP Connection
put libURLftpCommand("LIST","ftp://localhost/") into field "ModList" -- List the Mods in the Direcotry
end mouseUp
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: How to get a filelist of an ftp server?
It's extremely rare that you'd use root to log in via FTP. Double-check the settings for your FTP account, and try this to get a detailed description of the transactions with the server:
1. Make a new stack named "FTP Transcript" with a field named "log"
2. Run this in the Message Box:
libURLSetLogField the long id of fld "log" of stack "FTP Transcript"
Now when you do anything with libURL you'll see all of the transactions logged to that field. If there's a login error you should see a 503 error in that transcript.
1. Make a new stack named "FTP Transcript" with a field named "log"
2. Run this in the Message Box:
libURLSetLogField the long id of fld "log" of stack "FTP Transcript"
Now when you do anything with libURL you'll see all of the transactions logged to that field. If there's a login error you should see a 503 error in that transcript.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
Re: How to get a filelist of an ftp server?
There's no call to 'open' the URL, just use the get or put command to fetch the information.
HTH,
Jan Schenkel.
Code: Select all
on mouseUp
libURLSetFTPListCommand "NLST"
put URL "ftp://root:xxxx@localhost/" into field "ModList" -- List the Mods in the Direcotry
end mouseUp
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com
-
- Posts: 76
- Joined: Sat Nov 07, 2009 7:43 pm
Re: How to get a filelist of an ftp server?
Thank you Janschenkel
that´s working smart^^
Could you also tell me how I could get the selection in my Scrolling List field and use it to download the selected file via a download button?
I don´t have an idea how to do that.
I know how to specify a file to be downloaded but how can I use the Scrolling List field were the files are listened to download one of them or more?
Thanks,
Masterchief
that´s working smart^^
Could you also tell me how I could get the selection in my Scrolling List field and use it to download the selected file via a download button?
I don´t have an idea how to do that.
I know how to specify a file to be downloaded but how can I use the Scrolling List field were the files are listened to download one of them or more?
Thanks,
Masterchief
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
Re: How to get a filelist of an ftp server?
Use the hilitedLine property of the list field:
HTH,
Jan Schenkel
Code: Select all
put the hilitedLine of field "ModList" into tHilitedLine
put line tHilitedLine of field "ModList" into tFileName
Jan Schenkel
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com
-
- Posts: 76
- Joined: Sat Nov 07, 2009 7:43 pm
Re: How to get a filelist of an ftp server?
Thanks. This helps a lot but for the download I need also the FTP Path. I tried to include the Variable tFileName in the Download URL but it doesn´t work that easy. Do you know how I can add the filename I got through the selection to the end of the downloadpath or how to get the downloadpath of the selected File?
Thanks,
Masterchief
Thanks,
Masterchief
-
- Posts: 76
- Joined: Sat Nov 07, 2009 7:43 pm
Re: How to get a filelist of an ftp server?
Ah it seems I got it working (was quite easy^^)
The code I am unsing now is:
The last line is commented out because it´s working but in case it wouldn´t I already wrote another way I thought it could work;)
Could you please tell me what you think of my solution? I am new to revolution and would like to get some advises if this code works but is buggy in your eyes^^.
PS: Now I am working on Zipping the files to upload and Unzip the files that are downloaded but if I get problems there I will tell you
Regards,
Masterchief
The code I am unsing now is:
Code: Select all
-- put the selection of the ModListFile into the Variable tFileToDownload
put the hilitedLine of field "ModList" into tHilitedLine
put line tHilitedLine of field "ModList" into tFileToDownload
-- put the address of the file to download into a variable
put "ftp://root:xxx@localhost/mods/" into tDownloadLink
put tFileToDownload after tDownloadLink
-- put tDownloadLink & tFileToDownload into tDownloadLink
Could you please tell me what you think of my solution? I am new to revolution and would like to get some advises if this code works but is buggy in your eyes^^.
PS: Now I am working on Zipping the files to upload and Unzip the files that are downloaded but if I get problems there I will tell you

Regards,
Masterchief
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
Re: How to get a filelist of an ftp server?
Well, you can either
or
The libUrlDownloadToFile command has an optional third parameter, the callbackMessage which will be sent to your control aftet the download is finished. Also check out the UrlStatus function if you wish to provide updates while the download progresses.
HTH,
Jan Schenkel.
Code: Select all
put URL tDownloadLink into URL (binfile:" & tLocalPath)
Code: Select all
libUrlDownloadToFile tDownloadLink, tLocalPath
HTH,
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com