IOS and FTP

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

IOS and FTP

Post by Nakia » Sun Mar 04, 2012 2:29 am

Hi,

I am trying to add to my IOS app the ability to upload a file (stored in the documents directory) to a FTP server
that is located at an IP address (10.0.0.1) (at the moment just running on another PC in my house)..

In the IOS notes it mentions that LibURL isn't available for iOS so I am using this code but when I run in LiveCode no connection occurs to the FTP server. From my MAC I can manually connect to this FTP server just fine..note ftp server is FileZilla..
--
put the URL ("file:file.dat") into URL "ftp://USERNAME:PASSWORD@10.0.0.1
--

what is it that I am missing?
probably something really simple... :oops: :oops:

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7394
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: IOS and FTP

Post by jacque » Sun Mar 04, 2012 8:36 pm

Omit "the", a URL is a container, not a property:

put URL ("file:file.dat") into...

Your FTP URL isn't finished. It points to a domain (actually, localhost here) but without a file path, so the server has no place to put the data. It should be more like this:

"ftp://user:pass@xx.xx.xx/folder/file.dat"
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: IOS and FTP

Post by Nakia » Mon Mar 05, 2012 12:58 am

So it would look like

put URL ("file:file.ext") into URL "ftp://user:pass@xx.xx.xx/folder/file.ext"

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7394
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: IOS and FTP

Post by jacque » Mon Mar 05, 2012 4:03 am

Yes, exactly right.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: IOS and FTP

Post by Nakia » Mon Mar 05, 2012 5:34 am

Thanks kindly..

Can you point me in the direction of configuring this with error handling and progress bars?
Just some doco links would be fantastic..

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7394
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: IOS and FTP

Post by jacque » Mon Mar 05, 2012 6:59 pm

The best place is to look in the iOS release notes, which you can access under the Help menu. Look for the section called "Non-file URL access". It explains the syntax and how to check for progress so that you can update a progress bar. The "URLprogress" message you'll be trapping will also tell you if there's been an error.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: IOS and FTP

Post by Nakia » Mon Mar 05, 2012 8:53 pm

jacque wrote:The best place is to look in the iOS release notes, which you can access under the Help menu. Look for the section called "Non-file URL access". It explains the syntax and how to check for progress so that you can update a progress bar. The "URLprogress" message you'll be trapping will also tell you if there's been an error.
Thanks so much. I really appreciate your help.
P.S. I tried it with the correct syntax last night and it worked a treat :D

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: IOS and FTP

Post by Nakia » Tue Mar 06, 2012 10:27 am

Okay,

after looking into the dictionary and IOS release notes I have come up with this but am not having any success..(yet)
The file is uploading correctly, with the correct Line Endings (thanks) but I am not getting anything from the urlProgress i.e. the answer box is not appearing
no matter which message I configure it to look for.. "uploaded" "uploading" "error" etc etc. what calls the urlProgress message? is it automatic when the transfer begins or am I missing something to call it?

on uploadData
put URL ("file:flights.dat") into tFlightsDat
replace CR with CRLF in tFlightsDat
put "ftp://MVRS:VIMS1!@10.0.0.2/Score/flight.dat" into pUrl
put tFlightsdat into URL pUrl
end uploadData

on urlProgress pUrl, pStatus
if pStatus is "uploaded" then
answer "Finished Uploading with" with "OK"
end if
end urlProgress

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7394
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: IOS and FTP

Post by jacque » Tue Mar 06, 2012 7:06 pm

The best way to see what's going on would be to use a logging mechanism to see what's actually being reported. There are two main ways to do this; one is to write the data to stndout which you can read in the Console application. The other is to just put a temporary field on the card that will record everything that's happening. I wouldn't use "answer" because that blocks all messages until you dismiss the dialog.

If you use a temp field, then do something like this:

Code: Select all

on urlProgress pURL,pStatus
  put pStatus & cr after fld "temp"
end urlProgress
That will show you everything that's being sent back as the file uploads. It should give you information about what's going wrong.

You can also write to stndout like this if you prefer:

Code: Select all

on urlProgress pURL,pStatus
  put pStatus & cr 
end urlProgress
This will send the results to Console and doesn't require you to create a field, but it will only work in the simulator. To see what's happening, open the Console app while your stack is running in the simulator. Put your stack name into the filter field so you will only see messages that come from your stack. Then run your upload handler and watch the progress in the Console.

The urlProgress message is a system message that is activated automatically by the engine whenever an upload or download occurs. You don't need to do anything to trigger it, it's just another event the engine notifies you about.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: IOS and FTP

Post by Klaus » Tue Mar 06, 2012 7:13 pm

Hi Jaqueline,

Kia is using PUT:
...
put URL ("file:flights.dat") into tFlightsDat
replace CR with CRLF in tFlightsDat
put "ftp://MVRS:VIMS1!@10.0.0.2/Score/flight.dat" into pUrl
put tFlightsdat into URL pUrl
...
Is "put" working asynchroniously/with callbacks on iOS?
I don't have a iOS license so I have to guess...

And is this a valid filename on iOS:
put URL ("file:flights.dat") into tFlightsDat
?

I would rather think of something like:
...
put URL ("file:" & specialfolderpath("documents") & "/flights.dat") into tFlightsDat
...


Best

Klaus

P.S.
Will move this thread to the correct "iOS" forum.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7394
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: IOS and FTP

Post by jacque » Tue Mar 06, 2012 7:26 pm

I'm suspicious of it too, because on desktop "put" is blocking. But there is no other option in iOS and the release notes say that progress is reported. There is a single libURL command for downloading, but the only iOS option for uploading is "put" right now, (unless you want to POST to a url, which is also supported.)

If the Console or the temp field is empty, then my suspicions are correct and no progress is reported. But the release notes strongly imply that it should work.

You're right that she needs the documents folder or the cache folder in the file path. I didn't catch that; it needs to be changed. Apple has some rigid rules about temporary data storage, so I'd use the cache folder for this unless the file really is user-generated data.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: IOS and FTP

Post by Nakia » Tue Mar 06, 2012 11:34 pm

Thanks for your help.

I am setting the default folder to documents (using set special folder path) on an open card call so I didn't think I needed to add that for this function?
Can you further explain the cache folder as I'm unsure of what this is and it's purpose? I have been using the documents directory as my folder to read and write files from, is this going to cause me issues when I submit my app to apple?

Looking through the release notes it says that urlProgress is supported so I have been traveling down this road with this. I didnt consider the POST message as it is aimed at http whe I'm aiming at a FTP server..according to the iOS release notes.

So where would be the next step in testing this? Its not working in run mode in livecode either so I think it's something wrong with my code. I will add in a temporary field as suggested and see what populates into that as a first step..

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: IOS and FTP

Post by Nakia » Wed Mar 07, 2012 7:59 am

Okay,

So I tied to write pStatus to a temp field as you said and got nothing in the field. so I tried the console and got the below message which means the message is definitely there and I am just doing something wrong in my code. any ideas?

7/03/12 6:12:56.586 PM UIKitApplication:58DW393J99.com.kbtechnologies.scorepad[0x74f0]: uploaded

on uploadData
put URL ("file:flights.dat") into tFlightsDat
replace CR with CRLF in tFlightsDat
put "ftp://MVRS:VIMS1!@10.0.0.1/Score/flight.dat" into pUrl
put tFlightsdat into URL pUrl
end uploadData

on urlProgress pUrl, pStatus
put pStatus & cr after fld "temp"
end urlProgress






Note-- ended up with this code for console write which did show the message being populated in the console correctly.

on uploadData
put URL ("file:flights.dat") into tFlightsDat
replace CR with CRLF in tFlightsDat
put "ftp://MVRS:VIMS1!@10.0.0.1/Score/flight.dat" into pUrl
put tFlightsdat into URL pUrl
end uploadData

on urlProgress pUrl, pStatus
put pStatus & cr
end urlProgress

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: IOS and FTP

Post by Nakia » Wed Mar 07, 2012 8:29 am

Update,

It seems to just be when using run mode in LC.
If I now run in simulator it is updating fld "temp" with progress as described in the release notes..

Thanks for your help everyone.

P.s. I could still use an explanation of why I should be using the cache folder in place of documents so I can avoid pain when I submit this to apple for app store approval..

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

Re: IOS and FTP

Post by Klaus » Wed Mar 07, 2012 12:38 pm

Hi Kia,

please read "Files and Folder handling" in the "iOS Release Notes" (Menu: Help)
for more info aboput the different specialfolderpathnames.

But to ease your mind:
You may write into DOCUMENTS and CACHE folders, so that will be OK with Apple :D


Best

Klaus

Post Reply