FTP Upload on mobile

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
gepponline
Posts: 91
Joined: Tue Sep 03, 2013 1:53 pm

FTP Upload on mobile

Post by gepponline » Tue Mar 24, 2015 2:31 pm

Hi!
I have a button in my app that upload a file on a server via FTP. I've taken the example someewhere here in the forum.
I use this method 'cause i need the file created from my app to be accessible from my desktop pc. And it was not being an unrooted mobile. If you know any other way to export the file from mobile to desktop I'll appreciate it.

This is my code:

Code: Select all

on mouseUp
   put empty into field "esitoFTP"
--SAVE FILE
   put specialFolderPath("documents") & "/censimentofiliere.txt" into tFilePath
   put the text of field "testo" into URL ("file:" & tFilePath)
--SAVE ON FTP SERVER
   put tFilePath into tFileForUpload     
   set the itemdel to "/"
   put the last item of tFileForUpload into tFileName   
   --ftp://username:password@host/filepath
   put "MYFTPSERVERPATH" into FTPHOST
   put "MYUSER" into FTPUSER
   put "MYPASSWORD" into  FTPPASS
   
   # Connect the start the upload
   put "ftp://" & FTPUSER & ":" & FTPPASS & "@" & FTPHOST & tFileName into tDestination
 
   libURLSetStatusCallback "uploadProgress", the long ID of me
   libURLftpUploadFile tFileForUpload, tDestination, "uploadComplete"
   
end mouseUp

on uploadComplete pURL, pStatus
    put "Status Update:" && pStatus && return before field "esitoFTP"
end uploadComplete

on uploadProgress pURL, pStatus
    put "Status Update:" && pStatus && return before field "esitoFTP"
end uploadProgress
Using the desktop version all works correctly, testing it on the mobile it seems that the FTP functons don't work...
Any suggestions?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9834
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: FTP Upload on mobile

Post by FourthWorld » Tue Mar 24, 2015 2:55 pm

Both libURLftpUploadFile and libURLSetStatusCallback are described in the Dictionary as being available for desktop OSes only at this time.

This isn't as bad as it may seem, given that FTP is an unsecure protocol (passwords are sent in plain text), seldom used these days.

For posting files to serves it's more common to use HTTP, with a script on the server written in PHP, Python, or LiveCode to receive it. This gives you control over the upload without providing unfettered access to the server - much safer.

Here's an example of how to use LiveCode Server to receive a file sent via POST:
http://lessons.runrev.com/m/4070/l/4070 ... ode-server
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

gepponline
Posts: 91
Joined: Tue Sep 03, 2013 1:53 pm

Re: FTP Upload on mobile

Post by gepponline » Tue Mar 24, 2015 3:14 pm

I'll take a look at it!
Thank you!

gepponline
Posts: 91
Joined: Tue Sep 03, 2013 1:53 pm

Re: FTP Upload on mobile

Post by gepponline » Tue Mar 24, 2015 3:30 pm

I read the document but..it's not clera How can I automate this process?
In that example You hae to connect to the page and press the upload button....I want my program to upload automatically the file I need...
Could you help me?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9834
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: FTP Upload on mobile

Post by FourthWorld » Tue Mar 24, 2015 3:47 pm

The Web form in that example uses the POST command, which is also supported by LiveCode. See the POST command in the Dictionary.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

gepponline
Posts: 91
Joined: Tue Sep 03, 2013 1:53 pm

Re: FTP Upload on mobile

Post by gepponline » Tue Mar 24, 2015 4:02 pm

ok ;)
I'll test it!

gepponline
Posts: 91
Joined: Tue Sep 03, 2013 1:53 pm

Re: FTP Upload on mobile

Post by gepponline » Tue Mar 24, 2015 4:15 pm

so...

I have to create 2 files:

an HTML file (ie, uploadfile.html)
and a .lc file(ie. fileupload.lc) that contain the same code as the html plus other code...(why the same as the html??)

then upload them to my server.

Now my app should use the POST command.
In the post command i will use the HTML file path as "destination URL"
but..what should i use as "data"?? The url of the file i want to post like

Code: Select all

URL ("file:" & MyFilePath)
?

Is all correct?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9834
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: FTP Upload on mobile

Post by FourthWorld » Tue Mar 24, 2015 4:53 pm

When sending data from a LiveCode client to a LiveCode server, many options are possible and often relatively simple. For example, you stuff the HTML and image files into an array, serialize the array with arrayEncode, compress that and base64 for it for safe transport, and just sent that over the wire as POST data to reverse on the other side. Most of my client-server apps use encoded arrays for multi-part data to and from the server.

But if you need to allow standard tools like Web browsers to also use the server-side script, you'll want to format the POST data as multi-part form data. This is as tedious to describe as it is to write, so I wouldn't bother - instead, just dig into the libURL backscript in the IDE and copy it from there, along with any supporting handlers required.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

gepponline
Posts: 91
Joined: Tue Sep 03, 2013 1:53 pm

Re: FTP Upload on mobile

Post by gepponline » Tue Mar 24, 2015 5:06 pm

...maybe my bad english..but I understand Half of what you said in your last post.
you talk about encoding and decoding, base 64....
i "only" need to post a file to store it in a server so that i can download it from there with my desktop pc and then elaborate the file with my desktop application.


Best of all I should send an SQL statement to a web page an then the html page should execute it 'cause there are no support for oracle DB directly in Livecode.


:cry:

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9834
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: FTP Upload on mobile

Post by FourthWorld » Tue Mar 24, 2015 7:10 pm

You want to store these files in database records? What's the ultimate goal for those files?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9834
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: FTP Upload on mobile

Post by FourthWorld » Tue Mar 24, 2015 7:10 pm

You want to store these files in database records? What's the ultimate goal for those files?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

gepponline
Posts: 91
Joined: Tue Sep 03, 2013 1:53 pm

Re: FTP Upload on mobile

Post by gepponline » Wed Mar 25, 2015 9:26 am

No, sorry, maybe I didn't explain well.

I get some data from field.

I have to store this data in a DB.

Being impossible to connect directly the app with the DB I have 2 solutions:

1) Save a file with data locally on mobile, transfer it to a server. Then with another app in a desktop environment, elaborate the file creating queries to execute on the data in the DB

2) NOT CREATE THE FILE but send every single QUERY to an HTML page that execute query on the DB.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”