Page 1 of 1

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

Posted: Tue Jul 03, 2012 10:25 am
by d.m.holdawayGA2553
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..

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

Posted: Tue Jul 03, 2012 12:01 pm
by Klaus
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

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

Posted: Tue Jul 03, 2012 12:24 pm
by d.m.holdawayGA2553
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 ?

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

Posted: Tue Jul 03, 2012 12:36 pm
by Klaus
d.m.holdawayGA2553 wrote:i am thinking dare i ask my next question ?
This is a free country :D

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

Posted: Tue Jul 03, 2012 1:01 pm
by d.m.holdawayGA2553
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....

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

Posted: Tue Jul 03, 2012 1:48 pm
by Klaus
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

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

Posted: Tue Jul 03, 2012 2:11 pm
by d.m.holdawayGA2553
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!

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

Posted: Tue Jul 03, 2012 2:28 pm
by d.m.holdawayGA2553
when i use tUsername should it be

tUsername = "ftpusername"

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

Posted: Tue Jul 03, 2012 2:30 pm
by d.m.holdawayGA2553
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

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

Posted: Tue Jul 03, 2012 2:32 pm
by Klaus
I forgot an &
...
put tData into URL("ftp://" & tUN & ":" & tPW & "@xxx.com/file2.txt"')
...

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

Posted: Tue Jul 03, 2012 2:36 pm
by d.m.holdawayGA2553
i had already added the & it still errors

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

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

Posted: Tue Jul 03, 2012 2:36 pm
by d.m.holdawayGA2553
i had already added the & it still errors

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

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

Posted: Tue Jul 03, 2012 2:38 pm
by d.m.holdawayGA2553
i removed the ' at the end

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

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

Posted: Tue Jul 03, 2012 3:06 pm
by Klaus
Ah, yes, sorry, made in a hurry :D