List of files on server for download
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
List of files on server for download
I see that some people have touched on this topic but no definitive answer...
I have a splash screen that checks for the latest version of a Livecode file by reading a text file for a version number and this is great and works fine for what I need it to do. However, my application uses plenty of Quartam Files and to have a text file listing all the different version numbers will be a nightmare. I would like to look inside a directory on the server, where my updates are stored, list all the files in the directory and compare them to the local files. I understand that I can use detailed files to get all the information such as modified date, which is what I will use to determine which files need downloading but I have having trouble listing files on the server since it's an http server.
Is this method viable and if so, please help to achieve it.
I have a splash screen that checks for the latest version of a Livecode file by reading a text file for a version number and this is great and works fine for what I need it to do. However, my application uses plenty of Quartam Files and to have a text file listing all the different version numbers will be a nightmare. I would like to look inside a directory on the server, where my updates are stored, list all the files in the directory and compare them to the local files. I understand that I can use detailed files to get all the information such as modified date, which is what I will use to determine which files need downloading but I have having trouble listing files on the server since it's an http server.
Is this method viable and if so, please help to achieve it.
-
- VIP Livecode Opensource Backer
- Posts: 10053
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: List of files on server for download
If I were in your position I would consider making a single text file that's automatically generated by you for the various files you need to account for.
Both HTTP and FTP are notoriously inconsistent in their formatting of lists, so attempting to rely on either will eventually cause problems.
But a file you control will be very easy to work with, and if you're generating it yourself you could even enjoy a speed boost by posting it in gzip format using LC's built-in compress function.
FTP is of course too dangerous to use, but if you set up a shared SSH key on the server you can write a simple utility to generate your manifest file, compress it, and upload it via scp quickly and securely.
Alternatively, you could write a simple CGI with LiveCode Server or PHP to submit your updates via POST.
Personally, I find shared SSH keys so wonderfully convenient and secure that they're well worth the few minutes it takes to set it up.
Both HTTP and FTP are notoriously inconsistent in their formatting of lists, so attempting to rely on either will eventually cause problems.
But a file you control will be very easy to work with, and if you're generating it yourself you could even enjoy a speed boost by posting it in gzip format using LC's built-in compress function.
FTP is of course too dangerous to use, but if you set up a shared SSH key on the server you can write a simple utility to generate your manifest file, compress it, and upload it via scp quickly and securely.
Alternatively, you could write a simple CGI with LiveCode Server or PHP to submit your updates via POST.
Personally, I find shared SSH keys so wonderfully convenient and secure that they're well worth the few minutes it takes to set it up.
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
Re: List of files on server for download
Okay, wow.. that sounds just like the solution that I was going to dream up when I got bigger..
It all pretty much sounds like rocket science to me I'm afraid but I am going to take what you have given me and research it. I just think that a text file with all information in may be tedious unless I am looking at it from the wrong angle. Can you be more specific. How would I automatically create it and what would it contain? I cannot version a quartam file so it would have to be a manual versioning system?
Sorry for my epic lack of imagination here.

Sorry for my epic lack of imagination here.
-
- VIP Livecode Opensource Backer
- Posts: 10053
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: List of files on server for download
When we're lucky, imagination is always about two steps ahead of our current skills and experience.
This is useful as it helps keep us motivated to learn, and if there's any consistency with software development over time it's that it involves continual learning.
Client-server apps are tremendously rewarding to build, but by splitting an application's logic across two machines that communicate through a slender straw, they do involve more complexity than having everything running in one local app. No worries; you'll get where you need to be soon enough. We all start out as beginners.
To get this going, let's start with the basics on build on that: what info do you need to obtain about those files?
And is yours a dedicated server, or on a shared host?
With that, we can look toward the simplest ways to achieve what you're looking for.

Client-server apps are tremendously rewarding to build, but by splitting an application's logic across two machines that communicate through a slender straw, they do involve more complexity than having everything running in one local app. No worries; you'll get where you need to be soon enough. We all start out as beginners.
To get this going, let's start with the basics on build on that: what info do you need to obtain about those files?
And is yours a dedicated server, or on a shared host?
With that, we can look toward the simplest ways to achieve what you're looking for.
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
Re: List of files on server for download
Thank you!
I was angling toward having a small piece of code that would check on the http server which is on a shared host (where my updates take place) in a directory where I would copy any changed report files. On startup, the app would look in that folder, grab a list of files and compare them with locally stored files. If there is a difference (the modified date is more recent on the server files) it is copied to the client. I do understand that this is not the best method as sometimes that information is not accurate. Although I like to do things properly, this is also just an in-house app where the simplest workable approach will suffice.
I was angling toward having a small piece of code that would check on the http server which is on a shared host (where my updates take place) in a directory where I would copy any changed report files. On startup, the app would look in that folder, grab a list of files and compare them with locally stored files. If there is a difference (the modified date is more recent on the server files) it is copied to the client. I do understand that this is not the best method as sometimes that information is not accurate. Although I like to do things properly, this is also just an in-house app where the simplest workable approach will suffice.
-
- VIP Livecode Opensource Backer
- Posts: 10053
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: List of files on server for download
It occurred to me that it might take longer to explain the language elements needed here than to just illustrate them in action, so I took a moment to write rough drafts of two handlers that may help.
The first is used to produce the file that will be copied to the server, containing a list of modification dates for all files in a given local copy of that folder.
The second is used to download the list from the server and compare the mod date for a given file to the one for that file in the server list.
The keywords to review in the Dictionary here are: files function, directory global property, urlEncode function, and get url command.
Note that I threw this together off the cuff and haven't tested any of it, so if you run into issues consider that an exercise for the reader.
The first is used to produce the file that will be copied to the server, containing a list of modification dates for all files in a given local copy of that folder.
The second is used to download the list from the server and compare the mod date for a given file to the one for that file in the server list.
The keywords to review in the Dictionary here are: files function, directory global property, urlEncode function, and get url command.
Note that I threw this together off the cuff and haven't tested any of it, so if you run into issues consider that an exercise for the reader.

Code: Select all
-- Takes a path to a local folder and generates a list of
-- detailed info which can be used later for comparison,
-- writing the list to the Desktop:
on MakeFileList pFolderPath
-- Check arg:
if there is not a folder pFolderPath then
answer "No such folder: "& pFolderPath
exit to top
end if
-- Get the list of files:
put the directory into tSaveDir
set the directory to pFolderPath
put the detailed files into tFiles
set the directory to tSaveDir
--
-- Write it to the Desktop where you can get to it
-- easily for uploading:
put specialFolderPath("desktop")&"/MyFileList.txt" into tFile
put tFiles into url ("binfile:"& tFile)
end MakeFileList
-- Takes a local file path and compares the file's modification
-- date to one stored in a list on the server to see if the
-- server copy is more recent, returning true if the date on
-- the server is later than the local mod date, or false if not:
function HasFileChanged pFile
-- Check arg:
if there is not a file pFile then
answer "No such file: "& pFile
exit to top
end if
--
-- Get server list:
put "http://www.MyDomain/somefolder/MyFileList.txt" into tUrl
put url tUrl into tServerList
if the result is not empty then
answer "Error downloading file list: "& the result
exit to top
end if
--
-- Get local file mod date:
set the itemdel to "/"
put the directory into tSaveDir
put pFile into tDir
delete last item of tDir
set the directory to tDir
put the detailed files into tFiles
set the directory to tSaveDir
put urlEncode(last item of pFile) into tFileName
put lineoffset(cr& tFileName &",", cr& tFiles) into tLineNum
set the itemdel to comma
put item 5 of line tLineNum of tList into tLocalModDate
--
-- Get mod date from server list:
put lineoffset(cr& tFileName&",", tServerList) into tLineNum
if tLineNum = 0 then
answer "File not in server list: "& pFile
exit to top
end if
put item 5 of line tLineNum of tServerList into tServerModDate
--
-- Compare the two:
return (tServerModDate > tLocalModDate)
end HasFileChanged
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
Re: List of files on server for download
Thank you very much. I now fully understand the concept and will implement this and get back to you when I have done so.
Re: List of files on server for download
So I have done the following:
The file is a quartam file but when copied to the folder, it does not appear as a quartam file. It seems like it has been converted. Am I doing anything wrong?
Code: Select all
//Get a list of files on the server
-- Get server list:
put "http://10.0.0.101/mfgproupdate/MyFileList.txt" into tUrl
put url tUrl into tServerList
set the itemdelimiter to comma
repeat for each line tFile in tServerList
put tFilePath & "/" & item 1 of tFile into tFileToCheck
HasFileChanged tFileToCheck
if the result is true then
//download the file
put "http://10.0.0.101/mfgproupdate/components/" & item 1 of tFile into sUrl
load url sUrl
put URL sUrl into URL ("binfile:" & tFileToCheck)
unload sUrl
end if
end repeat
Code: Select all
on HasFileChanged pFile
-- Check arg:
if there is not a file pFile then
answer "No such file: "& pFile & " Do you wish to download?" with "YES" or "NO"
if it is "YES" then
return true
else
exit to top
end if
end if
--
--
-- Get local file mod date:
set the itemdel to "/"
put the directory into tSaveDir
put pFile into tDir
delete last item of tDir
set the directory to tDir
put the detailed files into tFiles
set the directory to tSaveDir
put urlEncode(last item of pFile) into tFileName
put lineoffset(cr& tFileName &",", cr& tFiles) into tLineNum
set the itemdel to comma
put item 5 of line tLineNum of tFiles into tLocalModDate
--
-- Get mod date from server list:
put lineoffset(tFileName&",", tServerList) into tLineNum
if tLineNum = 0 then
answer "File not in server list: "& pFile
exit to top
end if
put item 5 of line tLineNum of tServerList into tServerModDate
--
-- Compare the two:
return (tServerModDate > tLocalModDate)
end HasFileChanged