iOS FTP
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
iOS FTP
There have been a couple of posts in this forum about FTP in iOS, with seemingly mixed results.
Is anyone using FTP to "get" files from a site, downloaded for example to the "documents" folder, then referencing the downloaded file from within a stack?
I am needing this functionality for a project, and any input would be greatly appreciated.
Thanks!
:Todd
Is anyone using FTP to "get" files from a site, downloaded for example to the "documents" folder, then referencing the downloaded file from within a stack?
I am needing this functionality for a project, and any input would be greatly appreciated.
Thanks!
:Todd
Re: iOS FTP
Yes, I'm doing that. What's the problem?
14" MacBook Pro
Former LiveCode developer.
Now recovering.
Former LiveCode developer.
Now recovering.
Re: iOS FTP
Jellicle
The problem is that I don't know where to start.
I catch on fairly quickly, once I know the way. I just have no way of knowing how to start the process.
Can you point me in the right direction?
:Todd
The problem is that I don't know where to start.
I catch on fairly quickly, once I know the way. I just have no way of knowing how to start the process.
Can you point me in the right direction?
:Todd
Re: iOS FTP
Todd
Assuming it's a text file you want to read, write and play with, you could do this:
Read:
put url "ftp://username:password@yourdomain.com/textfile.txt" into dataFromFTP
Write:
put dataToFTP into URL "ftp://username:password@yourdomain.com/textfile.txt"
Once you have the data you can write and read it locally:
Write:
set the defaultFolder to specialFolderPath("Documents")
put dataToWriteToFile into URL ("file:usertext.txt")
Read:
set the defaultFolder to specialFolderPath("Documents")
put URL ("file:usertext.txt") into dataReadFromFile
Hope that helps get you started. There are more sophisticated ways of doing this, depending on your needs. For example if your files are big you may want to use libUrlDownloadToFile to get your files (see the iOS release notes).
Gerry
Assuming it's a text file you want to read, write and play with, you could do this:
Read:
put url "ftp://username:password@yourdomain.com/textfile.txt" into dataFromFTP
Write:
put dataToFTP into URL "ftp://username:password@yourdomain.com/textfile.txt"
Once you have the data you can write and read it locally:
Write:
set the defaultFolder to specialFolderPath("Documents")
put dataToWriteToFile into URL ("file:usertext.txt")
Read:
set the defaultFolder to specialFolderPath("Documents")
put URL ("file:usertext.txt") into dataReadFromFile
Hope that helps get you started. There are more sophisticated ways of doing this, depending on your needs. For example if your files are big you may want to use libUrlDownloadToFile to get your files (see the iOS release notes).
Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.
Former LiveCode developer.
Now recovering.
Re: iOS FTP
Gerry:
Thanks for the information. That helps immensely. As I mentioned in a previous post, I feel like I'm scripting at a kindergarten level. I can do basic things in LC, but the more sophisticated stuff eludes me.
If my files are larger than a text file or two, the libUrlDownload may be what I need. Per the iOS release notes:
libUrlDownloadToFile url, filename
Does the use of this follow the same syntax as your previous examples, or look completely different?
set the defaultFolder to specialFolderPath("Documents")
put libUrlDownloadToFile "ftp://username:password@yourdomain.com/large.file" into defaultFolder
???
Also, for larger files, can a progress bar be included, or an updated text field (XXX of XXX KB) to inform the user of progress?
Thanks, again. I really appreciate it!
:Todd
Thanks for the information. That helps immensely. As I mentioned in a previous post, I feel like I'm scripting at a kindergarten level. I can do basic things in LC, but the more sophisticated stuff eludes me.
If my files are larger than a text file or two, the libUrlDownload may be what I need. Per the iOS release notes:
libUrlDownloadToFile url, filename
Does the use of this follow the same syntax as your previous examples, or look completely different?
set the defaultFolder to specialFolderPath("Documents")
put libUrlDownloadToFile "ftp://username:password@yourdomain.com/large.file" into defaultFolder
???
Also, for larger files, can a progress bar be included, or an updated text field (XXX of XXX KB) to inform the user of progress?
Thanks, again. I really appreciate it!
:Todd
Re: iOS FTP
Hi Todd,
check the iOS Release Notes for differences in these commands between iOS and the desktop version!
Example:
libUrlDownloadToFile is blocking on iOS, so you may want to use "load" instead!
Hints:
1. I heard that setting "the defaultfolder" does not always work as exspected on iOS, so use concatenated filenames instead!
...
put (specialFolderPath("Documents") & "/the_file.jpg") into tLocalFile
...
2. "liburldownloadtofile" is a COMMAND, you used it as a function in your posting:
...
put (specialFolderPath("Documents") & "/the_file.jpg") into tLocalFile
libUrlDownloadToFile "ftp://username:password@yourdomain.com/ ... tLocalFile
...
Best
Klaus
check the iOS Release Notes for differences in these commands between iOS and the desktop version!
Example:
libUrlDownloadToFile is blocking on iOS, so you may want to use "load" instead!
Hints:
1. I heard that setting "the defaultfolder" does not always work as exspected on iOS, so use concatenated filenames instead!
...
put (specialFolderPath("Documents") & "/the_file.jpg") into tLocalFile
...
2. "liburldownloadtofile" is a COMMAND, you used it as a function in your posting:
...
put (specialFolderPath("Documents") & "/the_file.jpg") into tLocalFile
libUrlDownloadToFile "ftp://username:password@yourdomain.com/ ... tLocalFile
...
Best
Klaus
Re: iOS FTP
Thanks, Gerry and Klaus!
It must be way too early for me to attempt this now.
I'll give it a try with the information provided when I'm more awake
I'll let you know how it goes.
:Todd
It must be way too early for me to attempt this now.
I'll give it a try with the information provided when I'm more awake

I'll let you know how it goes.
:Todd
Re: iOS FTP
Several cups of coffee later...
I was able to finally get a successful transfer of a file on my remote server to the Documents folder in the iOS Simulator.
The code that worked was:
Still trying to figure out a progress indicator on download progress...
Now that 4.6 supports revZip, I'll then try to figure out how to unzip the file to the same directory, then delete the original file.zip.
Thanks for helping me on this: Gerry for the initial response, and Klaus for the breadcrumbs.
I was able to finally get a successful transfer of a file on my remote server to the Documents folder in the iOS Simulator.
The code that worked was:
Code: Select all
get URL "http://www.myserver.com/directory/file.zip"
put it into tFile
put tFile into url("file:" & specialFolderPath("Documents") & "/" & "file.zip")
Now that 4.6 supports revZip, I'll then try to figure out how to unzip the file to the same directory, then delete the original file.zip.
Thanks for helping me on this: Gerry for the initial response, and Klaus for the breadcrumbs.

Re: iOS FTP
Hi Todd,
you can save some typing and some memory by skipping the GET and IT and PUT INTO VAR part in your script:
...
put URL("http://www.myserver.com/directory/file.zip") into url("file:" & specialFolderPath("Documents") & "/" & "file.zip")
...
Best
Klaus
you can save some typing and some memory by skipping the GET and IT and PUT INTO VAR part in your script:
...
put URL("http://www.myserver.com/directory/file.zip") into url("file:" & specialFolderPath("Documents") & "/" & "file.zip")
...

Best
Klaus
Re: iOS FTP
Thanks for the tip Klaus!
I had to understand the long way before optimizing it
All my best!
:Todd
I had to understand the long way before optimizing it

All my best!
:Todd
Re: iOS FTP
Hi,
Is there a way to download a folder from an ftp/http server?
A little explanation to my question
___
Let's say that we know the folder's url but have no idea what's inside it.
When it's local, it's easy.
We can use the files and the folders functions to obtain the content of that particular folder.
Then cycle through that list(s) to do what we want to do, i.e. copy a folder with all its contents to another location.
But what about a remote folder, i.e. http://www.example.com/myMobileApp/myFolder/?
Is there a function exist or is it possible to write a function for the same purpose as the files and the folders?
Regards,
~ Ender Nafi
Is there a way to download a folder from an ftp/http server?
A little explanation to my question

Let's say that we know the folder's url but have no idea what's inside it.
When it's local, it's easy.
We can use the files and the folders functions to obtain the content of that particular folder.
Then cycle through that list(s) to do what we want to do, i.e. copy a folder with all its contents to another location.
But what about a remote folder, i.e. http://www.example.com/myMobileApp/myFolder/?
Is there a function exist or is it possible to write a function for the same purpose as the files and the folders?
Regards,
~ Ender Nafi
~... together, we're smarter ...~
__________________________________________
macOS Sierra • LiveCode 7 & xCode 8
__________________________________________
macOS Sierra • LiveCode 7 & xCode 8
Re: iOS FTP
Hi Ender,
short question, do you manage that server or are you talking about ANY server?
Best
Klaus
short question, do you manage that server or are you talking about ANY server?
Best
Klaus
-
- Livecode Opensource Backer
- Posts: 328
- Joined: Mon Dec 05, 2011 5:34 pm
- Contact:
Re: iOS FTP
Hi Ender,
As far as I know - using FTP (via the url route) you can only access specific files for upload/download. Folder directory access is restricted to full FTP login and command issuing processes. i.e. there is no way to send an "ls" command via an URL.
But, I don't know the full extent of LC's capabilities in the FTP front - so I'm sure there will be someone who can give a better answer.
If you actually own/manage the server then it is a lot easier - as you can setup tools on the server to allow remote "control" of stuff.
Cheers,
Dave
As far as I know - using FTP (via the url route) you can only access specific files for upload/download. Folder directory access is restricted to full FTP login and command issuing processes. i.e. there is no way to send an "ls" command via an URL.
But, I don't know the full extent of LC's capabilities in the FTP front - so I'm sure there will be someone who can give a better answer.
If you actually own/manage the server then it is a lot easier - as you can setup tools on the server to allow remote "control" of stuff.
Cheers,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.
Visit http://electronic-apps.info for released App information.
Re: iOS FTP
@Dave
Thanks for the reply,
actually it can be done via a php or javascript script but I'm not web programmer and I don't know how to embed a script to LC.
@Klaus
I own the server and I know the full path of the folder.
But I don't know how many files will be in that folder.
Think of it as a webpage of photo gallery.
The gallery scripts first list the content of the folder then they show it as a gallery.
I need that kind of functionality.
Regards,
~ Ender Nafi
Thanks for the reply,
actually it can be done via a php or javascript script but I'm not web programmer and I don't know how to embed a script to LC.
@Klaus
I own the server and I know the full path of the folder.
But I don't know how many files will be in that folder.
Think of it as a webpage of photo gallery.
The gallery scripts first list the content of the folder then they show it as a gallery.
I need that kind of functionality.
Regards,
~ Ender Nafi
~... together, we're smarter ...~
__________________________________________
macOS Sierra • LiveCode 7 & xCode 8
__________________________________________
macOS Sierra • LiveCode 7 & xCode 8
-
- Livecode Opensource Backer
- Posts: 328
- Joined: Mon Dec 05, 2011 5:34 pm
- Contact:
Re: iOS FTP
Hi Ender,
Not sure if Javascript can do ftp, and you can't embed PHP into LC
But, if you manage the server then you should have no problem in writing a little PHP script (or asp/c#/whatever!) that can read a directory and print the results as a text output (e.g.. one file name per line, return separated) - or whatever format you would prefer. This can be put anywhere on your server that is accessible from the web (but give the file a complicated name!) and have it require a special password/key phrase to do it's thing. If you have ever done any php then this should be pretty easy.
Then, from LC you just need to:
put url ("http://host.com/blah/dirgetter.php?secret=1234567") into my_files_on_server_var
Just like calling a web page, but without the html output (unless you want that!)
Because it's just text as an output the results can be read with a simple repeat for each line type construct.
You could enhance the script to take a folder path as a parameter, or much more. Because the actual stuff is being run on the server (by PHP or whatever) you don't need to try and circumvent server access restrictions. Altogether pretty easy - as long as you know some server side script!
*edit: just reread you message about not being a web programmer. You can probably find a suitable script online somewhere or ask a friendly web programmer to help you out a little. The basic script isn't really that difficult to write - there is not much to it.
Hope that helps,
Cheers,
Dave
Not sure if Javascript can do ftp, and you can't embed PHP into LC

But, if you manage the server then you should have no problem in writing a little PHP script (or asp/c#/whatever!) that can read a directory and print the results as a text output (e.g.. one file name per line, return separated) - or whatever format you would prefer. This can be put anywhere on your server that is accessible from the web (but give the file a complicated name!) and have it require a special password/key phrase to do it's thing. If you have ever done any php then this should be pretty easy.
Then, from LC you just need to:
put url ("http://host.com/blah/dirgetter.php?secret=1234567") into my_files_on_server_var
Just like calling a web page, but without the html output (unless you want that!)
Because it's just text as an output the results can be read with a simple repeat for each line type construct.
You could enhance the script to take a folder path as a parameter, or much more. Because the actual stuff is being run on the server (by PHP or whatever) you don't need to try and circumvent server access restrictions. Altogether pretty easy - as long as you know some server side script!
*edit: just reread you message about not being a web programmer. You can probably find a suitable script online somewhere or ask a friendly web programmer to help you out a little. The basic script isn't really that difficult to write - there is not much to it.
Hope that helps,
Cheers,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.
Visit http://electronic-apps.info for released App information.