FTP Upload on mobile device

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

Flo92
Posts: 16
Joined: Fri Jul 21, 2017 7:15 pm

FTP Upload on mobile device

Post by Flo92 » Wed Jul 26, 2017 10:36 am

Hi!
I tried to upload a created .txt-File from my app on my android-device. When I pushed the upload button it always says "App has unfortunately stopped". And my app is closed and no file is uploaded. I don't know if that is because of the FTP or not?
So I searched a bit on the forum and I don't know if I'm correct but is it the case that Livecode doesn't support FTP-Upload on a mobile device? Just for information: My FTP-code is working on the desktop-version
If so: Is there an easy possibility for an amateur like me to get an upload working?
My users do have to fill in a survey, the answers get written into a variable and then this variable should be written into a .txt-document and be uploaded onto my server so I can read it and put it into statistics.

Thanks in advance!

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

Re: FTP Upload on mobile device

Post by Klaus » Wed Jul 26, 2017 11:41 am

Hi Flo,

did you check ALL neccessary internet stuff in the standalone builder setting on the "Android" and "Inclusions" card?
And you should always check "the result" after an action that could fail, since it may give a hint on what's going on.

Code: Select all

...
put xyz into url("ftp:"...)
if the result <> EMPTY then
  answer "An Error occurred:" && the result
  exit to top
end if
...
Best

Klaus

Flo92
Posts: 16
Joined: Fri Jul 21, 2017 7:15 pm

Re: FTP Upload on mobile device

Post by Flo92 » Wed Jul 26, 2017 12:51 pm

Klaus wrote:Hi Flo,

did you check ALL neccessary internet stuff in the standalone builder setting on the "Android" and "Inclusions" card?
And you should always check "the result" after an action that could fail, since it may give a hint on what's going on.

Code: Select all

...
put xyz into url("ftp:"...)
if the result <> EMPTY then
  answer "An Error occurred:" && the result
  exit to top
end if
...
Best

Klaus
I did try various different settings, including everything I thought that is neccessary, as well as just ticking everything that's possible.
Thanks for the result-idea! Here is the result of my error-answer on the emulator (on my android device I only get the "app stopped running"-message)
An Error occurred:
"java.io.IOException: Unable to connect to server: Unable to change directories"

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

Re: FTP Upload on mobile device

Post by Klaus » Wed Jul 26, 2017 1:09 pm

Hi Flo,
Flo92 wrote:An Error occurred:
"java.io.IOException: Unable to connect to server: Unable to change directories"
OK, we have a hint, which does not tell me anything!? :D

But I'm sure other will chime in and help you further.


Best

Klaus

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: FTP Upload on mobile device

Post by FourthWorld » Wed Jul 26, 2017 3:51 pm

Why FTP specifically?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Flo92
Posts: 16
Joined: Fri Jul 21, 2017 7:15 pm

Re: FTP Upload on mobile device

Post by Flo92 » Wed Jul 26, 2017 5:02 pm

There's no need for FTP. It's just really easy for an amateur like me. So I thought it would be the quickest way to get to the finish line. If you have any suggestions that work fine and ideally aren't too hard to understand for someone with relatively few experience, I'd immediately try it!

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: FTP Upload on mobile device

Post by FourthWorld » Wed Jul 26, 2017 5:09 pm

Are these files being uploaded to your server, or do users upload to their own?

If yours, is it a shared host, VPS, or dedicated server?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Flo92
Posts: 16
Joined: Fri Jul 21, 2017 7:15 pm

Re: FTP Upload on mobile device

Post by Flo92 » Wed Jul 26, 2017 10:51 pm

It is uploaded to my server. I guess it is a shared hosting service (?). It's just some 2gb space at some german telecomunication service whereon I can also have a website running. When I enter the control center of my "hosting" I can choose between access via FTP/SSH/MySQL.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: FTP Upload on mobile device

Post by FourthWorld » Wed Jul 26, 2017 10:58 pm

Do you have the ability to run PHP, or a custom CGI like LiveCode?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Flo92
Posts: 16
Joined: Fri Jul 21, 2017 7:15 pm

Re: FTP Upload on mobile device

Post by Flo92 » Thu Jul 27, 2017 6:36 am

Well.. not yet, but I guess I'll just have to do some PHP-Tutorial then :D But just to be sure: Does it work 100% with PHP :D?

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: FTP Upload on mobile device

Post by SparkOut » Thu Jul 27, 2017 6:42 am

It can be done in php or other server side script. There are some things to help you along, such as http://forums.livecode.com/viewtopic.php?f=9&t=29357 using LC server.
There are some other scripts on this forum giving sample php code somewhere too.

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: FTP Upload on mobile device

Post by AxWald » Thu Jul 27, 2017 1:41 pm

Hi,

this code here works for me (LC 6.7.10 ("search required inclusions", permission: "Internet"), Android 5.0.1). Just tested again:

Code: Select all

on mouseUp
   --  setting up Vars:  --
   put URLEncode("myUserName") into myUSR  -- Username
   put URLEncode("mySecretPassWord") into myPSW  --  Password
   put "myDomain.org/" into myURL                        --  basic Domain name
   put "ftp://" & myUSR & ":" & myPSW \
         & "@" & myURL into myFTPDir                      -- connect it
   
   --  we need a unique filename:  --
   get the date && the long time
   convert it to dateitems  --  2017,7,27,13,44,55,5
   set itemdel to comma
   delete item 7 of it
   repeat for each item myItem in it
      put format("%02s",myItem) after myFileName
   end repeat                    --  => 20170727134455
   
   --  now we push it:  --
   put the long system date & CR & the long system time into URL (myFTPDir & myFileName & ".txt")   --  To FTP!
   answer "Pushed file!" & CR & the result
end mouseUp
You're sure you don't use a wrong "MyURL"? You need the main URL for logging in.
The file will end in the directory connected with the assigned user. Be sure you have permissions there.

Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

Flo92
Posts: 16
Joined: Fri Jul 21, 2017 7:15 pm

Re: FTP Upload on mobile device

Post by Flo92 » Thu Jul 27, 2017 9:04 pm

Okay.. So I don't know what or if I'm doing something wrong here, but I tried exactly your code, just with my FTP-Data in my chosen app, and then - just for the case my app causes some FTP-crash - I just did a new empty project with just a button on it. Both times it worked perfectly fine on Windows, the file was uploaded with the given name but both times I get a crash on my android device. I even tried it with my phone (Android 5.1.1) as well as my tablet (Android 6.0.1).
So yeah :D I don't know.. ^^

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: FTP Upload on mobile device

Post by AxWald » Fri Jul 28, 2017 2:41 pm

Hi,
Flo92 wrote:[...] Both times it worked perfectly fine on Windows, the file was uploaded with the given name but both times I get a crash on my android device. [...]
Really strange. I have code like this installed on various Android devices, never had problems with it (using it to provide log files/ telemetry on the FTP server).
When setting up the StandAlone I have only checked "Sign for development only", "Allow external storage" and "Internet permissions". Only the last should have a meaning here, and I'm sure you've checked it too. Any other settings are at default.

Besides, I'm using LC 6.7.10 comm. Just compiled the stack (just 1 button, as yours) with 8.1.3 comm., and it worked, too. Possible you're using tsNet? Cannot think of any other reason.

Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

Flo92
Posts: 16
Joined: Fri Jul 21, 2017 7:15 pm

Re: FTP Upload on mobile device

Post by Flo92 » Fri Jul 28, 2017 7:53 pm

Hi Axwald!
Really awkward. Would you mind uploading only a stack with a working button for FTP-Upload - but of course deleting your login-data beforehand - so I can erase my possible mistake :D?

Post Reply