Write to file using a FTP

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
JackBroughton
Posts: 9
Joined: Tue Oct 21, 2014 2:18 am
Location: Sydney, Australia

Write to file using a FTP

Post by JackBroughton » Thu Nov 26, 2015 3:04 am

Hi All,

I am building a routine that gets an order number from a text file on a server through FTP, increments that order number then saves the new, incremented order number back to the file.

I am stuck on the saving part. Here is my basic code. It gets the correct data out of the file, increments it but how do I put the new order number back?

Code: Select all

   put "ftp://"&" UNAME "&" : "&" PW "&"@"&" IP "&"/test/System Numbers" into tFolder
   put (tFolder & "/" & sPoint) into nFile
   put url nFile into tNumber
   add 1 to tNumber
   put (sCode & tNumber) into line 1 of url nFile
This was the only similar post I could find but there was no solution that worked and the responses stopped in 2010.

http://forums.livecode.com/viewtopic.ph ... FTP#p60212

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Write to file using a FTP

Post by Simon » Thu Nov 26, 2015 3:39 am

Hi Jack,
Unless you have some cool php, cgi or a liveCode server I don't think just FTP is what you want.
If the file was small enough and wasn't being requested by multiple users then I'd download the file, update it locally then upload it again.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

JackBroughton
Posts: 9
Joined: Tue Oct 21, 2014 2:18 am
Location: Sydney, Australia

Re: Write to file using a FTP

Post by JackBroughton » Thu Nov 26, 2015 3:58 am

Hi Simon,

Thank for you reply. I thought as such.

It is a tiny file (4kb's) but I do have multiple users accessing it.

Currently it is working as we mount the server using AFP then uses a Open, Write and Close process on the file. I wanted to try mimic that so we can move to mobile devices.

I think I will try using a php script to do it server side.

Regards
Jack

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Write to file using a FTP

Post by Simon » Thu Nov 26, 2015 4:04 am

Hi Jack,
This actually sounds like a job for mySQL, if you haven't worked with DB's this would be a great start. Simple DB, the most difficult part would be setting up the original DB on your server and cPanel can do most of that.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

AndyP
Posts: 615
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Re: Write to file using a FTP

Post by AndyP » Thu Nov 26, 2015 10:33 pm

Hi Jack,

Have to agree that this sounds like a db is the way to go. MySQL can handle concurrent actions from multiple users with ease.

If have LiveCode server installed on your hosting then you can use LiveCode to act as the parser to and from the db.

All the code you would need for this can be found here:

http://activethought.net/livecode-server/databases/

I'm using LiveCode server in a few of my projects serving around 200 users and have found the speed (in most cases) comparable with PHP.

All the best on your LiveCode explorations...
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search

JackBroughton
Posts: 9
Joined: Tue Oct 21, 2014 2:18 am
Location: Sydney, Australia

Re: Write to file using a FTP

Post by JackBroughton » Fri Nov 27, 2015 5:30 am

Hi Simon and Andy,

Thank you for the suggestions to use SQL and I may look at moving to a SQL DB soon.

As for my initial issue I found a very simple fix. In the below line, FTP has an issue with folders that have a space in them.

Code: Select all

put "ftp://"&" UNAME "&" : "&" PW "&"@"&" IP "&"/test/System Numbers" into tFolder
As soon as I changed System Numbers to SystemNumbers it all worked fine.

Code: Select all

put "ftp://"&" UNAME "&" : "&" PW "&"@"&" IP "&"/test/SystemNumbers" into tFolder

Post Reply

Return to “Internet”