ftp with iOS...

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Chrius
Posts: 19
Joined: Fri Jan 28, 2011 4:04 pm

ftp with iOS...

Post by Chrius » Wed Feb 23, 2011 4:45 pm

Hi all,

i've got a problem with this code (i mainly use an tutorial around), which work on "Run" mode, but not in the iphone simulator...
i thought ftp was supported on the last version, for iOS ? What am i doing wrong ?

constant FTPHOST = "host.com"
constant FTPUSER = "user@user.com"
constant FTPPASS = "mypassword"

on mouseUp

    # Start by getting the file to upload
    local tFileForUpload, tFileName
    
    # Get the name of the file for upload
    set the itemdel to "/"

put "/Users/xxxx/myfile.txt" into tFileForUpload

put "myfile.txt" into tFileName
    put empty into field 1
    
    # Connect the start the upload
    local tDestination
    put "ftp://" & FTPUSER & ":" & FTPPASS & "@" & "host.com/" & tFileName into tDestination
    libURLftpUploadFile tFileForUpload, tDestination, "uploadComplete"
end mouseUp

on uploadComplete pURL, pStatus
    put "Status Update:" && pStatus && return after field 1
end uploadComplete


Thanks for help

Chris

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

Re: ftp with iOS...

Post by Klaus » Wed Feb 23, 2011 4:58 pm

Hi Chris,

all this is in the iOS Release notes, which obviously noone ever cares to read... :roll:

The relevant part:
...
Note that the iOS engine does not support libUrl...
...

Please read the complete part yourself: Menu: Help -> iOS Release Notes
Page 13-15 in LC 4.5.3


Best

Klaus

Chrius
Posts: 19
Joined: Fri Jan 28, 2011 4:04 pm

Re: ftp with iOS...

Post by Chrius » Wed Feb 23, 2011 6:29 pm

Oh sorry about that... But i'm beginning on LiveCode, not so easy to find the good informations at the good place
i'll remember about release notes :)

so... i changed the line with the libUrl.... with

put tFileForUpload into url tDestination

like advised in RN
<<
To upload a file to an FTP server you can use: put tData into url “ftp://ftp.myftpserver.com
>>

again it works on the run mode, but not in the simulator...

any idea ?

Chris

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

Re: ftp with iOS...

Post by Klaus » Wed Feb 23, 2011 6:34 pm

Hi Chris,

hm, I did not yet work with FTP on iOS, but that is how it is supposed to work.

You could check "THE RESULT" immediately after the upload:

Code: Select all

...
put tFileForUpload into url tDestination
if the result <> empty then
  answer "An error occurred:" & CR & the result
end if
...
This might give you an hint on what's going wrong.

Best

Klaus

Chrius
Posts: 19
Joined: Fri Jan 28, 2011 4:04 pm

Re: ftp with iOS...

Post by Chrius » Tue Mar 22, 2011 3:27 pm

sorry to have not responded to this before...
i tried your solution, but i have no messages on the simulator, as if it was done, with no problem... but no transfer occurs...
i really don't find any solution... Can this be a bug ?
I don't think i'm the only one to use ftp on livecode ;)

Edit : it seems the problem comes from "the result"
if i "put" with or without errors, the result is always empty

here my code with the modification... :

put "ftp://" & FTPUSER & ":" & FTPPASS & "@" & "domain.com/" & tFileName into tDestination
if the result <> empty then
  answer "An error occurred:" & CR & the result
end if

and i have never messages appearing...

i tried to get "the result" with this :

put "ftp://" & FTPUSER & ":" & FTPPASS & "@" & "domain.com/" & tFileName into tDestination
answer "An error occurred:" & CR & the result

here i have a message "An error occurred:" (no value)
and only in "run mode", not in the simulator

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

Re: ftp with iOS...

Post by Klaus » Tue Mar 22, 2011 4:25 pm

Hi Chrius,

you need to read and copy/paste a bit more carefully!
Chrius wrote:Edit : it seems the problem comes from "the result"
No! "the result" is the only help we might get here and works well if used correctly!
Chrius wrote:

Code: Select all

...
put "ftp://" & FTPUSER & ":" & FTPPASS & "@" & "domain.com/" & tFileName into tDestination
   if the result <> empty then
        answer "An error occurred:" & CR & the result
  end if
...
Did you check "tDestination"? This only contains the STRING:
ftp://USERNAME:PASSWORD@domain.com/FILENAME
That's all! No hint to the local file on disk nor any internet action!
So the result is of course empty here!
Chrius wrote:i tried to get "the result" with this :
...
put "ftp://" & FTPUSER & ":" & FTPPASS & "@" & "domain.com/" & tFileName into tDestination
answer "An error occurred:" & CR & the result
...
Same as above and this time you did not CHECK the result, but only open a dialog with the result,
no matter if that is empty or not!

So rewrite your scripts, put some "URL" and "if the result <> empty then..." into the right places and tell us if that works 8)


Best

Klaus

Chrius
Posts: 19
Joined: Fri Jan 28, 2011 4:04 pm

Re: ftp with iOS...

Post by Chrius » Tue Mar 22, 2011 5:06 pm

Ouch !!!!
my mistake... too fast reading....
i have this new code ;)

put tFileForUpload into url tDestination
if the result <> empty then
  answer "An error occurred:" & CR & the result
end if

there are no messages appearing, and the put into url works, i have my file on my ftp... but again only on run mode.
in simulator, i have no messages, but it does nothing.

i'm going mad :)

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

Re: ftp with iOS...

Post by Klaus » Tue Mar 22, 2011 5:37 pm

Hi Chrius,

syntax looks OK now, can you try this on a real device?
The Simulator does not always work as exspected 8)

Best

Klaus

Chrius
Posts: 19
Joined: Fri Jan 28, 2011 4:04 pm

Re: ftp with iOS...

Post by Chrius » Tue Mar 22, 2011 6:04 pm

not for now :(
i'm waiting to know livecode better to get an Apple dev account

but i have one more (last ?) question...
i wonder if the problem doesn't come from the location of my file...

put "/Users/xxxx/myfile.txt" into tFileForUpload

complete path on computer, which, i think, will not be recognized by the simulator ? am i wrong ?
so i tried to get the path "/Documents/myfile.txt", and i copied the file in the path :
"/library/Application support/iphone simulator/4.2/Applications/somestrangecaracters/documents"
it doesn't work...
i tried too to affect the special folder :
set the defaultFolder to specialFolderPath("Documents")
but no way :(

perhaps the simulator is wrong here... or me ;)

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

Re: ftp with iOS...

Post by Klaus » Tue Mar 22, 2011 6:13 pm

Hi Chrius,

I think the Simulator has access to your complete harddisk,
so using any absolute path(!) to any file should work.

And dont forget the keyword URL or you will only get the path
to the file instead of its contents! 8)

Important hint:
"specialFolderPath("Documents")" is different on iOS than on the Mac!


Best

Klaus

Chrius
Posts: 19
Joined: Fri Jan 28, 2011 4:04 pm

Re: ftp with iOS...

Post by Chrius » Wed Mar 23, 2011 5:22 pm

Hi Klaus,

you helped me on the other thread of this forum, on "iOS FTP" thread :)
http://forums.runrev.com/phpBB2/viewtop ... =49&t=7135

I used your suggestion :
put URL("http://www.myserver.com/directory/file.zip") into url("file:" & specialFolderPath("Documents") & "/" & "file.zip")
(in fact file > ftp, not http > file)
nice, I know really have the content of the file (it wasn't the case before)

but it seems the simulator have problems with this (as other tests with ftp I did)... Very strange...
i always have the message "timed out"
in you have any idea...
if no, i'll keep for the moment this code, until i can test it on a real device... Perhaps it will work better

Thank you Klaus for all !!!!

ctflatt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 243
Joined: Sun Dec 06, 2009 12:24 am
Contact:

Re: ftp with iOS...

Post by ctflatt » Wed Mar 23, 2011 9:30 pm

Chrius:

How large is the file you're transferring?

:Todd

Chrius
Posts: 19
Joined: Fri Jan 28, 2011 4:04 pm

Re: ftp with iOS...

Post by Chrius » Thu Mar 24, 2011 6:56 pm

In my test it is 8 Ko
very fast so :)

Why ?

Post Reply