Page 2 of 2
Re: iOS FTP
Posted: Fri Sep 28, 2012 2:47 am
by endernafi
Dave thank you very much,
It costed me a night, but I've managed it.
I wrote a simple php script which lists the files and folders,
and called it with
put url ("") into sentence.
Then a little iteration & enumeration and voila;
it worked like a charm
Thanks again,
Best,
~ Ender Nafi
Re: iOS FTP
Posted: Fri Sep 28, 2012 3:06 am
by endernafi
Oh and,
if someone needs same kind of functionality, here are my codes:
LiveCode:
Code: Select all
on updateTheContent
if isThereConnection() then
put url ("http://www.example.com/mobileapp/theContent/listTheFiles.php") into theFileList
replace "<br>" with return in theFileList
replace "../theContent/" with empty in theFileList
repeat for each line theFile in theFileList
put "http://www.example.com/mobileapp/theContent/" & theFile into theSource
put getTheLocation() & "myTemp" into theTempFile
put getTheLocation() & "theContent/" & theFile into theTarget
libUrlDownloadToFile theSource, theTempFile
if ((there is a file theTempFile) and (calcTheFileSize(getTheLocation(), "myTemp") > 0)) then
#answer "file downloaded"
delete file theTarget
#answer "old file deleted"
put url("binfile:" & theTempFile) into url("binfile:" & theTarget)
#answer "new file written"
delete file theTempFile
#answer "temp file deleted"
end if
end repeat
end updateTheContent
and PHP:
Code: Select all
<?php
ob_start();
session_start();
$theFolderArray=array();
$theFolderArray[0] = "../theContent";
$theFolderCount = count($theFolderArray);
for ($i=0;$i<$theFolderCount;$i++) {
$theFolder=$theFolderArray[$i];
$theFileArray = array();
$open = opendir($theFolder);
while($theFile=readdir($open)) {
if ($theFile != "." && $theFile != "..") {
if(is_file("$theFolder/$theFile")){
$theFileArray[] = $theFile;
}
}
}
$theFileCount = count($theFileArray);
closedir($open);
for ( $i=0 ; $i < $theFileCount ; $i++ ) {
echo "$theFolder/$theFileArray[$i]<br>";
}
}
?>
Regards,
~ Ender Nafi Elekçioğlu
Re: iOS FTP
Posted: Fri Sep 28, 2012 7:44 am
by dave_probertGA6e24
Hi Ender,
Excellent. Glad I could help a bit.
Nice piece of code - you could change the "<br>" bit to use "\n" (slash - n = newline) in the PHP (near the end) - that would save you the replace in LC. It's only a tiny change though and might not be worth it if you prefer readability of the data itself.
I'm happy to see you exploring the integration of the 2 languages in this way. I've been a PHP programmer for 10 years and find it invaluable when working with server-side data (files or database). I'm sure others feel the same way about their favourite Server-Side languages too.
Cheers,
Dave
Re: iOS FTP
Posted: Fri Sep 28, 2012 11:15 am
by Klaus
Yep, that's what I wanted to propose, too!
Put a little "filelisting.php" script into that folder, so you can GET the content of that folder via HTTP
and then loop through these files via FTP and download them.
Best
Klaus
Re: iOS FTP Download folder content
Posted: Sat Sep 21, 2024 4:54 pm
by trevix
I restart this post because I have a similar problem: download a hole folder from "MY" web site.
Actually, in order to list the content of a directory, I am using TsNet with this code (works on OSX and mobile). No PHP needed:
Code: Select all
function ListWebFolderContent
--gWebMirror is a global array with gWebMirror["username"]["xxx"] and gWebMirror["password"]["yyy"]
tsNetSetTimeouts 30, 0, 5000, 60000, 30, 1000
put tsNetCustomSync("ftp://ftp.mydomain.it//www.mydomain.it/myfolder/", "NLST", tHeaders, tRecvHeaders, tResult, tBytes,gWebMirror["settings"]) into tData
if tResult is not 226 then --something is wrong
put tResult & cr & tRecvHeaders into msg
else --got list of myfolder content
filter lines of tData where char 1 of each <> "." --directory list contains a few "." and ".."
if tData is empty then
put "The folder is empty" & cr & tResult & cr & tRecvHeaders into msg
else
return tData
end if
end if
end ListWebFolderContent
My user case is that my standalone, when needed, is updating itself downloading from my web site a folder, which replace the existing one inside the standalone.
The content of the folder is mixed (files and folders) and around 40MB.
I am wondering which is the best way for the download: should I have the web folder zipped and unzip it on arrival? Or using TsNet I may be able to download a "hole" unzipped folder?
UnZipping on LC10 takes a while and I would avoid that.
Re: iOS FTP UPDATE
Posted: Sun Sep 22, 2024 5:09 pm
by trevix
Update.
I spent the old day but I was able to download files and folders contents from my web space, using
tsNetGetFile (from the lesson) and a recursive script (to list each file directory). File by file, directory by directory, instead that a simpler unique folder download (which may be impossible I think).
Sort of...
While this is rather complex and not exactly fast in LC (compared to a FTP program like Transmit), my actual problem is that tsNetGetFile does not create the folders if the file to be saved has a directory like
"/Users/trevix/Desktop/Referi_/AppIcons/icon_57x57.png"
like it happens if you save a file using
put xx into URL "file:/Drive/Folder/File".
Creating all the empty folders directories before running the tsNetGetFile loop script, can be quite complicated (and I am not even started to understand eventual problems on mobiles).
Any suggestions?
Should I go back to Zip/unzip?