Anyone have a function or script for uploading files from a web browser with a bash script? I know this is possible to do with Perl, I'm wondering if the same is possible using only bash.
Sean Carolan wrote:
Anyone have a function or script for uploading files from a web browser with a bash script? I know this is possible to do with Perl, I'm wondering if the same is possible using only bash.
um, you download from a webserver, and upload to one.
wget or curl can be used to download a file from a webserver.
uploading a file TO a webserver requires more infromation, such as what upload protocols and authentication does the server support/require? one method that can be used is DAV aka WebDAV, cadaver is a command line WebDAV client included with CentOS.
If I'm dealing with a webserver I manage I more frequently use scp and/or rsync to move files to/from the server, this typically requires user credentials suitable for a ssh login on the server
$ scp user@hostname:path/to/filename localpath
or
$ scp path/to/localfile user@hostname:path/to/remote
exchange ssh key credentials first so no password is required.
Am 04.01.2009 um 01:13 schrieb John R Pierce:
Sean Carolan wrote:
Anyone have a function or script for uploading files from a web browser with a bash script? I know this is possible to do with Perl, I'm wondering if the same is possible using only bash.
um, you download from a webserver, and upload to one.
wget or curl can be used to download a file from a webserver.
uploading a file TO a webserver requires more infromation, such as what upload protocols and authentication does the server support/require? one method that can be used is DAV aka WebDAV, cadaver is a command line WebDAV client included with CentOS.
I think he wants to have a shell-script that can process upload-file- forms, displayed in browsers.
AFAIK, the general rule is: don't do that (CGI programming with shell- scripts).
Use something else (PHP as CGI, if you don't want to have mod_php).
Rainer
I think he wants to have a shell-script that can process upload-file- forms, displayed in browsers.
AFAIK, the general rule is: don't do that (CGI programming with shell- scripts).
Use something else (PHP as CGI, if you don't want to have mod_php).
Good to know, thanks for the info. I will probably go with PHP as it seems the simplest option.
From: Sean Carolan scarolan@gmail.com
Anyone have a function or script for uploading files from a web browser with a bash script? I know this is possible to do with Perl, I'm wondering if the same is possible using only bash.
I use curl. It can be a bit tricky if you use POSTDATA... Here's the function I use:
# upload_file <URL> <POSTDATA> <FILE> function upload_file() { URL="$1" DATA="$2" FILE="$3" PARAMS="-F "file=@$FILE"" IFS="&" for PARAM in $DATA do PARAMS="$PARAMS -F "$PARAM"" done IFS=" " eval `echo curl $PARAMS $URL 2>/dev/null` if [ $? -ne 0 ]; then echo "curl error $?"; fi }
JD
On Mon, Jan 05, 2009 at 04:30:58AM -0800, John Doe wrote:
From: Sean Carolan scarolan@gmail.com Anyone have a function or script for uploading files from a web browser with a bash script? I know this is possible to do with Perl, I'm wondering if the same is possible using only bash.
I use curl. It can be a bit tricky if you use POSTDATA... Here's the function I use:
# upload_file <URL> <POSTDATA> <FILE> function upload_file() { URL="$1" DATA="$2" FILE="$3" PARAMS="-F "file=@$FILE"" IFS="&" for PARAM in $DATA do PARAMS="$PARAMS -F "$PARAM"" done IFS=" " eval `echo curl $PARAMS $URL 2>/dev/null` if [ $? -ne 0 ]; then echo "curl error $?"; fi }
JD
Hi John,
Just curious here, from Sean's request info, this script would run on the web server the user was connected to. How will this curl command be able to "pull" the file from the user's system up on to the server?
I know that curl can be used to send data to or from a server, but it usually seems to be running on the user's system (eg the browser side of the relationship). In this case wouldn't it be running on the server?
I seem to be missing part of the flow here.
Curl is my favorite CLI web tool. If it can do this I want to understand it. As I understand it, The user's machine would need to be running an http (or ftp) service in order to fulfill this curl request originating from the server. I keep rechecking the curl man page and I'm still missing it.
I've probably overlooked something basic. :-)
JK Jeff Kinz
From: Sean Carolan Anyone have a function or script for uploading files from a web browser with a bash script? I know this is possible to do with Perl, I'm wondering if the same is possible using only bash.
Just curious here, from Sean's request info, this script would run on the web server the user was connected to. How will this curl command be able to "pull" the file from the user's system up on to the server?
Hum... I replied to quickly. I thought he was on the uploader side and not on the server side. My bad... ^_^ JD