Page 1 of 1

FTP & iOS: weird things…

Posted: Mon Oct 08, 2012 12:21 pm
by rmuzzini
hi all.
looking for a LC/iOS master… :-)

i'm developing an app for both desktop and mobile platforms (LC 5.5.2, iOS 5.1, OSX). this app has access to a local sqlite database. after the startUp, a copy of the internal DB is copied into the "documents" folder, if it needs (i.e. at the very first launch, at least). then, the user has to click an "enter" btn to read the data. this btn checks the db file version getting the current one via url/php code from my server. if it needs, the update procedure starts.

and that's the weird thing:
this is the code i'm using

Code: Select all

#btn "enter"
on mouseUp
   checkDB
   go to cd "db home"
end mouseUp

command checkDB
   put "Loading…" into fld "status"
   put the defaultFolder into oldDefFolder
   set the defaultFolder to specialFolderPath("Documents")
   put the files into tCurVersion
   set the defaultFolder to oldDefFolder
   filter tCurVersion with "*.sql"
   if tCurVersion is empty then put copyDB() into tCurVersion //eg: tCurVersion = "db1.sql"

   put "Checking version…" into fld "status"
   put kBaseUrl & kCheck into theURL
   put URL theURL into tLastVer     //eg: tLastVer = "db2.sql"
   if tLastVer <> tCurVersion then answer question localString("update_avalilable") with "OK" OR localString("cancel")
   if it is "OK" then put updateDB(tCurVersion, tLastVer) into tCurVersion
   
   put specialFolderPath("Documents") & SLASH & tCurVersion into gPathDB //save the db file path in  a global
   put "" into fld "status"
end checkDB

function updateDB tCurVersion, tLastVer
   #eg: tCurVersion = "db1.sql", tLastVer = "db2.sql"
   if tCurVersion <> tLastVer then
      put specialFolderPath("Documents") & SLASH & tCurVersion into tFilePath
      delete file tFilePath
      put "ftp://" & uDB & ":" & pDB & kBaseFTPUrl & tLastVer into tSource
      put specialFolderPath("Documents") & SLASH & tLastVer into tDestination
      put URL(tSource) into URL ("binfile:"&tDestination)
      put the result
   end if  
   return tLastVer
end updateDB

function copyDB
   …
   return tCurVersion
end copyDB

it works like a charm on authoring, on desktop and even on iOS simulator.
whilst on iPad device the result is empty (then no errors during the ftp download), the file is updated (old one goes away, new one appears) BUT the file is 0 byte.

any ideas? what's wrong with my code?
:-(

Re: FTP & iOS: weird things…

Posted: Wed Oct 10, 2012 2:23 pm
by rmuzzini
no idea, it seems.
so my code is good…?

but the downloaded file is still 0 bytes…
:-/

no one here got the same weird situation?
any example of "ftp file download on iOS" good practice?
after a deep seek in this forum i didn't find anything useful for my situation.
or i'm wrong?

Re: FTP & iOS: weird things…

Posted: Thu Oct 11, 2012 11:43 am
by endernafi
Hi rmuzzini,

I've faced the exact same issue a couple months ago.
I think the problem is about put url into url form.
It doesn't get along with http or ftp servers.
So, I suggest using libURLDownloadToFile command, instead.
You can change the line:

Code: Select all

put URL(tSource) into URL ("binfile:"&tDestination)
with this one:

Code: Select all

libURLDownloadToFile tSource,tDestination
Please give it a try and share your result.
Oh and, remember that this command is non-blocking on desktop but blocking on mobile platforms.


Best,

~ Ender Nafi

Re: FTP & iOS: weird things…

Posted: Thu Oct 11, 2012 2:24 pm
by rmuzzini
endernafi wrote:Hi rmuzzini,

I've faced the exact same issue a couple months ago.
I think the problem is about put url into url form.
It doesn't get along with http or ftp servers.
So, I suggest using libURLDownloadToFile command, instead.

~ Ender Nafi
hi.
thank you for your message.

no luck, anyway.
i forgot to mention in my prevoius post i alredy tried the libURL way.

i also tried "load URL":

Code: Select all

command test
[…]
        put "ftp://" & uDB & ":" & pDB & kBaseFTPUrl & tLastVer into tSource
        libURLSetStatusCallback "showProgress", the long ID of me
        load URL tSource with message "downloadComplete"
[…]
end test
command downloadComplete pURL, pStatus
[…]
        put last item of pURL into tFilename
        put gPrefPath & slash before tFileName
        put URL pURL into URL ("binfile:" & tFileName)
        answer information "Done"
        unload pURL
[…]
end downloadComplete
using a test button, that performs this update task only. again, it works everywhere but on device.
in this case, anyway, no file is downloaded at all (neither the 0 bytes file, i mean).
the (other) weird thing is that the callback give no feedback at all and message "downloadComplete" is not sent.
as the libURLDownloadToFile (or the load URL) command never start…


:-/

Re: FTP & iOS: weird things…

Posted: Thu Oct 11, 2012 2:34 pm
by rmuzzini
endernafi wrote:Hi rmuzzini,
I think the problem is about put url into url form.
~ Ender Nafi
another comment: please, note that the "put URL into URL" form works as expected when i copy the internal db file into the device/app/"Documents" folder at the first launch.
i think the problem be related to the FTP command execution.
please, note also that the devices i used fot tests have both wi-fi and 3G. same issue, despite of the choice. and the internet connection is obviously on (the version check is correct).

so? other LC user with the same problem? or i am (we 2 are…) just a black swan?!
:-(

Re: FTP & iOS: weird things…

Posted: Thu Oct 11, 2012 3:02 pm
by endernafi
please, note also that the devices i used fot tests have both wi-fi and 3G. same issue, despite of the choice.
Well, that would be my second guess. No luck, huh?

I couldn't think any other possible reason giving that your code works perfect on desktop and on simulator.
It works, right; only problem is actual device?

Sorry that I -or nobody else- couldn't help more :(

Something in your code bothers me, though.
I don't know whether it's related to your problem or not, but allow me to share.

Code: Select all

put "Checking version…" into fld "status"
put kBaseUrl & kCheck into theURL
put URL theURL into tLastVer     //eg: tLastVer = "db2.sql"
Does this work?
LiveCode Dictionary states that
Use the URL keyword to access the contents of a local file or a file accessible on the Web.
I mean, the contents...
Doesn't the last sentence download the kCheck file and put the contents of it into the variable tLastVer?
Or am I missing something here?


Best,

~ Ender Nafi

Re: FTP & iOS: weird things…

Posted: Thu Oct 11, 2012 4:06 pm
by rmuzzini
endernafi wrote:
Something in your code bothers me, though.
I don't know whether it's related to your problem or not, but allow me to share.

Code: Select all

put "Checking version…" into fld "status"
put kBaseUrl & kCheck into theURL
put URL theURL into tLastVer     //eg: tLastVer = "db2.sql"
Does this work?
LiveCode Dictionary states that
Use the URL keyword to access the contents of a local file or a file accessible on the Web.
I mean, the contents...
Doesn't the last sentence download the kCheck file and put the contents of it into the variable tLastVer?
Or am I missing something here?


Best,

~ Ender Nafi
yes. we're both right.
:)
kCheck is "check.php" (for example). and it is a simple one-line php file
echo 'lastdb.sql'
i simply compare 2 file name, editing the php file when needed…
:wink:


anyway, er… forget (and forgive) me.
:lol:
after a deepest check, i realized the problem probably was… the server firewall… i forgot to open the ftp port to external (for this silly reason on MY mac all tests were good…).
:oops:

however, now i can see - in the firewall log - the device contacting my ftp server. the strange thing (a new one) is that, even if my kBaseFTPUrl has ":21" as final part, after the first handshake the server receives (and denies) request to other high ports…
but this is another question i'll resolve in some way…

thanks again for your collaboration.

Re: FTP & iOS: weird things…

Posted: Thu Oct 11, 2012 4:20 pm
by gpb01
rmuzzini wrote:
endernafi wrote:Hi rmuzzini,
...
i forgot to mention in my prevoius post i alredy tried the libURL way.
i also tried "load URL":
...
Please remeber that the libURL is NOT implemented on mobile except for ONE function ... "libURLDownloadToFile".

Check on the dictionary ... ALL the other functions are ONLY for Desktop.

Guglielmo

P.S. : .. the same is also for the (HTTP) "PUT <data> TO URL <url>" which is NOT implemented on mobile

Re: FTP & iOS: weird things…

Posted: Thu Oct 11, 2012 4:26 pm
by endernafi
@rmuzzini

Ok, I'm happy that you're able to define the problem thus finding the way to the solution...

Cheers mate 8)


~ Ender Nafi

Re: FTP & iOS: weird things…

Posted: Thu Oct 11, 2012 5:26 pm
by jacque
iOS is case-sensitive. Try using "documents" in the file path instead of "Documents".

Re: FTP & iOS: weird things…

Posted: Thu Oct 11, 2012 5:53 pm
by Klaus
jacque wrote:iOS is case-sensitive. Try using "documents" in the file path instead of "Documents".
Sure, but specialfolderpath("WhatEveR") is a Livecode function, which is NOT case sensitive, so this should (sic!) not have any effect! 8)

Re: FTP & iOS: weird things…

Posted: Fri Oct 12, 2012 8:30 am
by rmuzzini
gpb01 wrote: Please remeber that the libURL is NOT implemented on mobile except for ONE function ... "libURLDownloadToFile".

Check on the dictionary ... ALL the other functions are ONLY for Desktop.

Guglielmo

P.S. : .. the same is also for the (HTTP) "PUT <data> TO URL <url>" which is NOT implemented on mobile

hi, gpb01.
thanks for the tip.

anyway, i don't know which LC version you're talking about. with mine (5.5.2), i can confirm that
put URL ("binfile:"& tFile1) into URL ("binfile:"&tFile2)
works with no error (app compiled for iOS 4.3 and even iOS 5.1).
from the dictionary:

Code: Select all

The iOS engines does not support 'libUrl' but allows you to use put in the background.
also, in my dictionary

Code: Select all

load [URL] url [with message callbackMessage]
is claimed to be iOS compliant.

btw, i resolved my issue.
no bugs in my code ;).
just bugs in my head: it was a matter or firewall&ftp ports messed up (OSX FTP server is a pain, in my opinion… and my security policy too, indeed…)
:)

as workaround, i simply moved my file into the apache root and set my app accessing it using "http get".
works perfectly.

thank you all again for the support.

Re: FTP & iOS: weird things…

Posted: Fri Oct 12, 2012 10:57 am
by gpb01
rmuzzini wrote: hi, gpb01.
thanks for the tip.

anyway, i don't know which LC version you're talking about. with mine (5.5.2), i can confirm that
put URL ("binfile:"& tFile1) into URL ("binfile:"&tFile2)
works with no error (app compiled for iOS 4.3 and even iOS 5.1).
from the dictionary:

Code: Select all

The iOS engines does not support 'libUrl' but allows you to use put in the background.
also, in my dictionary

Code: Select all

load [URL] url [with message callbackMessage]
is claimed to be iOS compliant.
....
Hi,
yes, yes, you can compile and you can run ... pity that DOES NOTHING !

From the "LiveCodeNotes-5_5_3_rc_2-iOS" (5.5.3 RC-2) :

The iOS engine supports the following non-file URL access methods:
• GET for http, https and ftp URLs
• POST for http and https URLs
• PUT for ftp URLs


so, as you can read, the HTTP GET and HTTP POST are supported, but for the put ONLY the FTP PUT is implemented and NOT the HTTP PUT ;)

Guglielmo

Re: FTP & iOS: weird things…

Posted: Fri Oct 12, 2012 12:15 pm
by rmuzzini
gpb01 wrote:
rmuzzini wrote:
anyway, i don't know which LC version you're talking about. with mine (5.5.2), i can confirm that
put URL ("binfile:"& tFile1) into URL ("binfile:"&tFile2)
works with no error (app compiled for iOS 4.3 and even iOS 5.1).
....
Hi,
yes, yes, you can compile and you can run ... pity that DOES NOTHING !

Guglielmo
hi.
actually, what i meant is:
in my app i use

Code: Select all

put URL ("binfile:"& tFile1) into URL ("binfile:"&tFile2) //that's just a file copy
and

Code: Select all

put URL theURL into theVar //that's a HTTP get, after all
and both do what they have to do: the file is copied, the url is loaded.

;)

cheers.

Re: FTP & iOS: weird things…

Posted: Fri Oct 12, 2012 1:14 pm
by gpb01
rmuzzini wrote: hi.
actually, what i meant is:
in my app i use

Code: Select all

put URL ("binfile:"& tFile1) into URL ("binfile:"&tFile2) //that's just a file copy
and

Code: Select all

put URL theURL into theVar //that's a HTTP get, after all
and both do what they have to do: the file is copied, the url is loaded.
Obviously ... you DON'T DO an HTTP PUT and, if you read my note, I still have spoken about HTTP PUT.

As you have specified, your first PUT is just a local file copy and the second PUT, technically, is not a put but an HTTP GET ... so ... ;)

Guglielmo