iOS FTP

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

endernafi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 296
Joined: Wed May 02, 2012 12:23 pm
Contact:

Re: iOS FTP

Post by endernafi » Fri Sep 28, 2012 2:47 am

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 8)

Thanks again,


Best,

~ Ender Nafi
~... together, we're smarter ...~
__________________________________________

macOS Sierra • LiveCode 7 & xCode 8

endernafi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 296
Joined: Wed May 02, 2012 12:23 pm
Contact:

Re: iOS FTP

Post by endernafi » Fri Sep 28, 2012 3:06 am

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
~... together, we're smarter ...~
__________________________________________

macOS Sierra • LiveCode 7 & xCode 8

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Contact:

Re: iOS FTP

Post by dave_probertGA6e24 » Fri Sep 28, 2012 7:44 am

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
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

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

Re: iOS FTP

Post by Klaus » Fri Sep 28, 2012 11:15 am

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

trevix
Posts: 1081
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Re: iOS FTP Download folder content

Post by trevix » Sat Sep 21, 2024 4:54 pm

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.
Trevix
OSX 14.6.1 xCode 15 LC 10 RC1 iOS 15> Android 7>

trevix
Posts: 1081
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Re: iOS FTP UPDATE

Post by trevix » Sun Sep 22, 2024 5:09 pm

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?
Trevix
OSX 14.6.1 xCode 15 LC 10 RC1 iOS 15> Android 7>

Post Reply