Page 1 of 1

How to get a filelist of an ftp server?

Posted: Sat Dec 05, 2009 5:04 pm
by MasterchiefJB
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

Re: How to get a filelist of an ftp server?

Posted: Sat Dec 05, 2009 5:20 pm
by FourthWorld
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"

Re: How to get a filelist of an ftp server?

Posted: Mon Dec 07, 2009 4:44 pm
by Janschenkel
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.

Re: How to get a filelist of an ftp server?

Posted: Mon Dec 07, 2009 7:47 pm
by MasterchiefJB
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

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
Do you know why this happens?

Re: How to get a filelist of an ftp server?

Posted: Mon Dec 07, 2009 8:34 pm
by FourthWorld
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.

Re: How to get a filelist of an ftp server?

Posted: Mon Dec 07, 2009 8:46 pm
by Janschenkel
There's no call to 'open' the URL, just use the get or put command to fetch the information.

Code: Select all

on mouseUp
   libURLSetFTPListCommand "NLST"
   put URL "ftp://root:xxxx@localhost/" into field "ModList" -- List the Mods in the Direcotry
end mouseUp
HTH,

Jan Schenkel.

Re: How to get a filelist of an ftp server?

Posted: Tue Dec 08, 2009 4:20 pm
by MasterchiefJB
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

Re: How to get a filelist of an ftp server?

Posted: Wed Dec 09, 2009 7:02 am
by Janschenkel
Use the hilitedLine property of the list field:

Code: Select all

put the hilitedLine of field "ModList" into tHilitedLine
put line tHilitedLine of field "ModList" into tFileName
HTH,

Jan Schenkel

Re: How to get a filelist of an ftp server?

Posted: Wed Dec 09, 2009 3:18 pm
by MasterchiefJB
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

Re: How to get a filelist of an ftp server?

Posted: Wed Dec 09, 2009 3:40 pm
by MasterchiefJB
Ah it seems I got it working (was quite easy^^)

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
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 :D

Regards,
Masterchief

Re: How to get a filelist of an ftp server?

Posted: Thu Dec 10, 2009 7:07 pm
by Janschenkel
Well, you can either

Code: Select all

put URL tDownloadLink into URL (binfile:" & tLocalPath)
or

Code: Select all

libUrlDownloadToFile tDownloadLink, tLocalPath
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.