Page 1 of 1
Count files on external server?
Posted: Sun Nov 18, 2012 6:37 am
by joel.epsteinBUS31vi
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
Re: Count files on external server?
Posted: Sun Nov 18, 2012 8:00 am
by FourthWorld
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.).
Re: Count files on external server?
Posted: Sun Nov 18, 2012 4:02 pm
by joel.epsteinBUS31vi
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
Re: Count files on external server?
Posted: Sun Nov 18, 2012 4:40 pm
by Klaus
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
Re: Count files on external server?
Posted: Sun Nov 18, 2012 5:46 pm
by joel.epsteinBUS31vi
Thanks so much! That certainly did the trick.
I truly appreciate the time you took to provide me with this helpful solution.
Joel
Re: Count files on external server?
Posted: Sun Nov 18, 2012 6:14 pm
by FourthWorld
Sorry - I forgot to put the service specifier in my earlier example URL:
get url "
ftp://user:password@www.projectiveart.com/PAApp/pix/"
Re: Count files on external server?
Posted: Sun Nov 18, 2012 6:58 pm
by joel.epsteinBUS31vi
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
Re: Count files on external server?
Posted: Sun Nov 18, 2012 9:30 pm
by jacque
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.
Re: Count files on external server?
Posted: Wed Dec 19, 2012 7:01 am
by Nakia
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?
Re: Count files on external server?
Posted: Wed Dec 19, 2012 11:04 am
by Klaus
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?
Nakia wrote:Would implementing that PHP script above work for FTP also?
No, PHP will only work over HTML.
Best
Klaus
Re: Count files on external server?
Posted: Wed Dec 19, 2012 11:33 am
by Nakia
Nah not too hard but wanted to check there was not
A function to do it before I attempt it..
Thanks for the feedback