trying to populate a field from a txt file on ftp server

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
d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

trying to populate a field from a txt file on ftp server

Post by d.m.holdawayGA2553 » Tue Jul 03, 2012 10:25 am

hello,

i have followed the both the lessons on handling text and writing to a file

http://lessons.runrev.com/s/lessons/m/4 ... ng-to-file

but i cant seem to get it to work.

the code in my button to fetch the URL is

Code: Select all

put URL "ftp://******@vps2.******.co.uk/sh/availability.txt" into field "availability"


i have sent the permissions on the file and the folder to 777

any advice is welcome..

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

Re: trying to populate a field from a txt file on ftp server

Post by Klaus » Tue Jul 03, 2012 12:01 pm

Hi,

you may need to add user name and password for this FTP account:
...
put urlencode(tUserName) into tUN
put urlencode(tPassWord) into tPW
put URL "ftp://" & tUN & ":" tPW & "@vps2.******.co.uk/sh/availability.txt" into field "availability"
...
## URLENCODE is only necessary if the username /password contains SPACES or any non ascii chars,
## but won't hurt if always used :-)

Best

Klaus

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

Re: trying to populate a field from a txt file on ftp server

Post by d.m.holdawayGA2553 » Tue Jul 03, 2012 12:24 pm

thanks Klas thats a massive help, i have added the code.

i had access to another server and it worked without the username and password.

i am thinking dare i ask my next question ?

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

Re: trying to populate a field from a txt file on ftp server

Post by Klaus » Tue Jul 03, 2012 12:36 pm

d.m.holdawayGA2553 wrote:i am thinking dare i ask my next question ?
This is a free country :D

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

Re: trying to populate a field from a txt file on ftp server

Post by d.m.holdawayGA2553 » Tue Jul 03, 2012 1:01 pm

its a bit of a big question.

ok..

i have two fields one is now populated with the contents of the txt file, what i want to do is highlight the lines i want and move them into the other field and then upload that field into a new file.

then saving the orignal file.

i have managed to copy the highlighted txt to the other field but the highlighted txt still remains

code

Code: Select all

on mouseUp
   put the selectedtext of field "content" into gMove
   remove selectedtext of field "content"
   put gMove into field "newcontents"
end mouseUp
and i also cant get the contents of the new field to upload to the new txt file.

code for contents to file is

Code: Select all

put field "newcontents" into URL "http://blahblah.com/file2.txt"
i wanted to understand this before i moved into datagrids....

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

Re: trying to populate a field from a txt file on ftp server

Post by Klaus » Tue Jul 03, 2012 1:48 pm

Hi,

this won't work with HTTP, unless you POST your data to a PHP or LiveCode server script,
which finally writes the file to the server hd.

But this can be done with FTP!

Code: Select all

...
## tData = the data you want to write to file2
put urlencode(tUserName) into tUN
put urlencode(tPassWord) into tPW
put tData into URL("ftp://" & tUN & ":" tPW & "@xxx.com/file2.txt"')
## check the rdesult!
## If empty, ali sfine!
if the result <> empty then
  anser "Error" && the result
end if
...
Best

Klaus

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

Re: trying to populate a field from a txt file on ftp server

Post by d.m.holdawayGA2553 » Tue Jul 03, 2012 2:11 pm

if i am handling data such as name, email address, telephone number - records...

should i be looking to use a database then instead of a text file?

thanks for all the help!

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

Re: trying to populate a field from a txt file on ftp server

Post by d.m.holdawayGA2553 » Tue Jul 03, 2012 2:28 pm

when i use tUsername should it be

tUsername = "ftpusername"

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

Re: trying to populate a field from a txt file on ftp server

Post by d.m.holdawayGA2553 » Tue Jul 03, 2012 2:30 pm

Klaus wrote:Hi,

this won't work with HTTP, unless you POST your data to a PHP or LiveCode server script,
which finally writes the file to the server hd.

But this can be done with FTP!

Code: Select all

...
## tData = the data you want to write to file2
put urlencode(tUserName) into tUN
put urlencode(tPassWord) into tPW
put tData into URL("ftp://" & tUN & ":" tPW & "@xxx.com/file2.txt"')
## check the rdesult!
## If empty, ali sfine!
if the result <> empty then
  anser "Error" && the result
end if
...
Best

Klaus
this returns an error.

button "Button": compilation error at line 15 (Expression: missing ')' before factor) near "tPW", char 40

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

Re: trying to populate a field from a txt file on ftp server

Post by Klaus » Tue Jul 03, 2012 2:32 pm

I forgot an &
...
put tData into URL("ftp://" & tUN & ":" & tPW & "@xxx.com/file2.txt"')
...

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

Re: trying to populate a field from a txt file on ftp server

Post by d.m.holdawayGA2553 » Tue Jul 03, 2012 2:36 pm

i had already added the & it still errors

button "Button": compilation error at line 15 (Expression: missing ')' before factor) near "'", char 52

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

Re: trying to populate a field from a txt file on ftp server

Post by d.m.holdawayGA2553 » Tue Jul 03, 2012 2:36 pm

i had already added the & it still errors

button "Button": compilation error at line 15 (Expression: missing ')' before factor) near "'", char 52

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

Re: trying to populate a field from a txt file on ftp server

Post by d.m.holdawayGA2553 » Tue Jul 03, 2012 2:38 pm

i removed the ' at the end

put tData into URL("ftp://" & tUN & ":" & tPW & "@xxx.com/file2.txt")

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

Re: trying to populate a field from a txt file on ftp server

Post by Klaus » Tue Jul 03, 2012 3:06 pm

Ah, yes, sorry, made in a hurry :D

Post Reply