Page 1 of 1

file upload to server

Posted: Wed Nov 09, 2011 1:59 am
by Steve Denney
Hi, I've got a livecode product utility. It handles ordering and updating the database etc.

I need users to be able to upload image files to an online store (i.e. when updating or adding products).

They need to do this from within the poduct utility.

I'm happy to use either 1. libURLftpUploadFile or 2. posting to php to do this.

Any solution will be much appreciated,

Steve

Here's what I've tried so far; I can't get either method to work.

First 1...

I've tried using :

put "C:/test_file.txt" into tFileForUpload
put "ftp://userName:password@theDomainName/w ... t_file.txt" into tDestination
libURLftpUploadFile tFileForUpload, tDestination

I've also tried http: in place of ftp:

Neither worked. Nothing appears to happen.

Then 2.

I've already used posting to php to update the online mysql database and that works just fine, but the submit button on an html page for an upload is a little different...

<form action="upload_file.php" method="post" enctype="multipart/form-data"> apparently creates a $_FILES array

whereas the usual post <form action="welcome.php" method="post"> simply populates a $_POST array

And (of course) livecode has to replace the submit button's action.

Once again any solution would be great, thanks

Re: file upload to server

Posted: Wed Nov 09, 2011 6:50 am
by bangkok
Hello,

Here is a stack you can work with.

Be sure to put your own ftp server address, login and password (at the top of stack's script).

This stack allows you to :
-select a file
-upload the file
-it shows a progress bar and handle errors

Re: file upload to server

Posted: Wed Nov 09, 2011 7:25 am
by Steve Denney
Hi Bangkok, thanks, I did simplify my efforts a little though, I already got hold of a (very) similar stack called Download_Upload.rev (which I didn't mention firstly to keep things simple and 2ndly 'cause I couldn't find where I got it from to to properly credit the creator).

Anyway, using either of these uploaders I get the stack's custom error message if I use the stack code as written, but the message comes whatever password, details etc I put in.

If I alter the script to http (which apparently helped someone in an earlier post) I get no error message, but no success message either.

I've tried all sorts of variations too, my login details work with dreamweaver but when used in the "ftp://userName:password@theDomainName/w ... t_file.txt" format they fail or with 'http:' they do nothing at all.

Any ideas?

Re: file upload to server

Posted: Wed Nov 09, 2011 9:17 am
by bangkok
I can assure you : it works.

From 2 different machines, I can upload successfully files to my ftp server. I just did it.

I made one mistake though :

the line

Code: Select all

put gRepertoireImage&the last item of tFileForUpload into tFileName
should be
put the last item of tFileForUpload into tFileName
(otherwise, the word "gRepertoireImage" whould be added to the name of the uploaded file)

So to summarize, I see only 3 solutions :

-you have a network/internet connection issue (firewall ?)

-you made a mistake with your login and/or password.

-you have an issue with the rights of your login and the directory of the ftp server

Re: file upload to server

Posted: Thu Nov 10, 2011 1:11 am
by Steve Denney
What you say makes sense, yet, I've shut down the firewall, confirmed login details and rang my service provider who told me ftp should work fine.

I've now tried all 3 of livecode's upload commands. The put command is the only one that yields useful result information. It's telling me: error 530 Login incorrect
BUT if I type the ftp URL syntax into my browser address bar:
ftp://login:password@domain_name/www/htdocs/ (minus the upload file name test.jpg) I get straight in (as logged in).

I've tried replacing the domain name with the ip address (in case it wasn't being resolved),
and creating a template file on the server, in case file creation somehow wasn't working.

No joy, and I've spent almost 2 days on this.

And the sad truth is I don't even really need it to work on our server (although it would save me work) I really need it to work on future client's websites (thought fills me with horror).

I'm going to start another thread, and beg for a php post solution. However if anyone comes up with a lc ftp solution it'd be great.
Thanks
Steve

Re: file upload to server

Posted: Thu Nov 10, 2011 8:40 am
by bangkok
Steve Denney wrote: I'm going to start another thread, and beg for a php post solution. However if anyone comes up with a lc ftp solution it'd be great.
Thanks
You should not give up !

Some other thoughts :

-I've you tried actually to copy a file to your ftp server, using the login and password and a regular FTP client (like Filezilla) ?
it would be good to try it, just to be sure that rights are okay.
My point : maybe rights are not okay, you can just connect, read the directory content, but not write into it.

-use a "way around" : try the LiveCode stack with another FTP server, and see what's going on. That would help to see that everything is fine and working as it should be.

-have you tried the stack with another PC ?

It has to work. It would be really annoying to use a php script. Your clients deserve the right to use an app that is able to connect to ftp server. :)

Re: file upload to server

Posted: Thu Nov 10, 2011 12:36 pm
by BvG
maybe try the simpler "put" form instead of liburlftpupload (for testing porpouse):

Code: Select all

put "this is a test" into theText
put theText into url "ftp://Login:PW@ValidURL/test.txt"
Note: if your password or login contains chars that are not allowed in urls, you need to urlencode them before using them in ftp commands from LC (see the urlEncode() function in the dictionary). For example:

normal:
Login: björnke
password: 12@e*dd[4#

urlencoded:
Login: bj%9Arnke
PW: 12%40e*dd%5B4%23

Re: file upload to server

Posted: Thu Nov 10, 2011 8:39 pm
by Steve Denney
Urlencode...
That's it BvG. I can't thank you enough, it's such a weight off my shoulders, really is.
And thanks Bangkok for sticking with this. As you can probably guess I've been losing trust in runrev over the last year or so--bad experiences with both the web and server platforms.
So! My faith in livecode (and causality ) is somewhat restored :D
Thanks again
Steve

Re: file upload to server

Posted: Wed Jun 18, 2014 12:15 am
by Peregrine
Hey, thanks, bangkok. I was having some of my own issues with libURLftpUploadFile, and your example stack was just what I needed to see it work.

Re: file upload to server

Posted: Wed Jun 18, 2014 1:46 am
by FourthWorld
Unless this is for your own personal use you may want to replace the FTP call with a call to a CGI that handles file uploads. FTP sends login credentials in plain text, so anyone using the app (or any interloper) could see the network stream and get control over that account on your server.

Re: file upload to server

Posted: Wed Jun 18, 2014 4:23 am
by Peregrine
Thanks, Richard. I'm aware of the vulnerability, and it should be OK for this little project. Really looking forward to having SFTP in LC, though.