Count files on external server?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
joel.epsteinBUS31vi
Posts: 135
Joined: Thu Sep 13, 2012 10:25 pm

Count files on external server?

Post by joel.epsteinBUS31vi » Sun Nov 18, 2012 6:37 am

Hi all -

I've seen how it's possible to use the defaultfolder and files() to get access to a specific place on a local machine. But what I want to do is count the number of files in a directory that exists on a remote server. Is there a handy way to do that?

Thanks so much.

Joel

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Count files on external server?

Post by FourthWorld » Sun Nov 18, 2012 8:00 am

Via FTP this is a one-liner in LiveCode - just pass the name of the folder to the "get url" command, e.g.:

get url "rg|pwd@mydomain.com/folder/subfolder/"

For other protocols (HTTP, etc), security considerations will usually require that such info be obtained from a program on the server designed to allow such access, such as a CGI script (which can be easily written in RevServer if needed).

With FTP, also note that the range of implementation of the FTP spec varies broadly, so you may be able to rely on getting the list of file names, but the format of the data returned may not be the same from server to server (sometimes has the date, sometimes not, sometimes the date is in one format, sometimes another, etc.).
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

joel.epsteinBUS31vi
Posts: 135
Joined: Thu Sep 13, 2012 10:25 pm

Re: Count files on external server?

Post by joel.epsteinBUS31vi » Sun Nov 18, 2012 4:02 pm

Thanks for your speedy response.

Unfortunately, I'm still rather new at LiveCode and am having trouble implementing your suggestion.

I tried this:

Code: Select all

  
   get url "user:password@www.projectiveart.com/PAApp/pix/"
   put it into tFolderToSearch
   set the defaultfolder to tFolderToSearch
   put the files into tAllFiles 
   answer tAllFiles
   answer the number of lines of tAllFiles
but that just gave me the list of files in my application directory.

I tried various options for the get url including using a pipe (|) instead of a colon between the user and password
I also tried using user:password@ftp://...

None of that seemed to work.

Could you please point me in the right direction?

Thanks so much.

Jole

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Count files on external server?

Post by Klaus » Sun Nov 18, 2012 4:40 pm

Hi Joel,

setting "the folder" and getting "the files" will ONLY work on your local machine,
but NOT on any server on the internet!

If you have access to the sever you could put a little PHP file into the directory where you need to "get the files" from.

Put this into a textfile, save it as "filelisting.php" and copy the file to your server:

Code: Select all

<?php
if ($handle = opendir('.')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "$file\n";
        }
    }
    closedir($handle);
}
?>
Then you can:
...
put url("http://www.your_server.com/whatever_directory/filelisting.php" into fld "list of files on server"
...

Best

Klaus

joel.epsteinBUS31vi
Posts: 135
Joined: Thu Sep 13, 2012 10:25 pm

Re: Count files on external server?

Post by joel.epsteinBUS31vi » Sun Nov 18, 2012 5:46 pm

Thanks so much! That certainly did the trick.

I truly appreciate the time you took to provide me with this helpful solution.

Joel

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Count files on external server?

Post by FourthWorld » Sun Nov 18, 2012 6:14 pm

joel.epsteinBUS31vi wrote:get url "user:password@www.projectiveart.com/PAApp/pix/"[/code]
Sorry - I forgot to put the service specifier in my earlier example URL:

get url "ftp://user:password@www.projectiveart.com/PAApp/pix/"
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

joel.epsteinBUS31vi
Posts: 135
Joined: Thu Sep 13, 2012 10:25 pm

Re: Count files on external server?

Post by joel.epsteinBUS31vi » Sun Nov 18, 2012 6:58 pm

Thanks, Richard. But I'm afraid I'm still confused.

When I use that line of code, I thought the result would be put into "it"

but unfortunately when I do that, "it" is always empty.

What am I doing wrong?

Thanks.

Joel

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Count files on external server?

Post by jacque » Sun Nov 18, 2012 9:30 pm

Most servers require the full path to the folder, starting at the home location, so you probably need this:

get url "ftp://user:password@projectiveart.com/p ... PAApp/pix/"

If your server uses "www" instead of "public_html" for the web folder, substitute that. If the folder you want to look at isn't in your web directory, then you'd need a different path, starting from the home directory.

This is just for FTP, when using HTML URLs, the more standard URL works.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: Count files on external server?

Post by Nakia » Wed Dec 19, 2012 7:01 am

FourthWorld wrote:Via FTP this is a one-liner in LiveCode - just pass the name of the folder to the "get url" command, e.g.:

get url "rg|pwd@mydomain.com/folder/subfolder/"

For other protocols (HTTP, etc), security considerations will usually require that such info be obtained from a program on the server designed to allow such access, such as a CGI script (which can be easily written in RevServer if needed).

With FTP, also note that the range of implementation of the FTP spec varies broadly, so you may be able to rely on getting the list of file names, but the format of the data returned may not be the same from server to server (sometimes has the date, sometimes not, sometimes the date is in one format, sometimes another, etc.).
Is there any way in FTP to return just the list of file names in the queried directory (minus all the dates,size's, rights etc)
Would implementing that PHP script above work for FTP also?

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Count files on external server?

Post by Klaus » Wed Dec 19, 2012 11:04 am

Hi Nokia,
Nakia wrote:...Is there any way in FTP to return just the list of file names in the queried directory (minus all the dates,size's, rights etc)
I don't think so, it will return whatever the server was set up to return!
Is it really that difficult to get rid of the stuff you don't need? 8)
Nakia wrote:Would implementing that PHP script above work for FTP also?
No, PHP will only work over HTML.


Best

Klaus

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: Count files on external server?

Post by Nakia » Wed Dec 19, 2012 11:33 am

Nah not too hard but wanted to check there was not
A function to do it before I attempt it..

Thanks for the feedback

Post Reply