Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

How to upload file without using FTP?

by madtoperl (Hermit)
on May 24, 2006 at 08:50 UTC ( [id://551303]=perlquestion: print w/replies, xml ) Need Help??

madtoperl has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: How to upload file without using FTP?
by McDarren (Abbot) on May 24, 2006 at 08:59 UTC
    No offense intended, but that code of yours is pretty ugly. And you're un-necessarily trying to re-invent a wheel that already exists and works perfectly.

    Personally, I would be using Net:SCP. Or alternatively, you might want to use Net:FTP

    --Darren

Re: How to upload file without using FTP?
by zentara (Archbishop) on May 24, 2006 at 10:44 UTC
    You can use many different things to upload it... lwp, wget, curl, or even pure sockets. Here is an lwp based uploader with a Tk front-end -> tk-http-file-upload-w-progress You can rip out the Tk code if you want, and have a console app

    Here is the cgi which receives it.

    #!/usr/bin/perl use warnings; use strict; use CGI; use CGI::Carp 'fatalsToBrowser'; #my $maxsize = 1024 * 100; #max 100K my $maxsize = 1024 * 20000; #max 20M #$CGI::POST_MAX= $maxsize; # max 100K posts !not working right? #$CGI::DISABLE_UPLOADS = 1; # no uploads my $query = new CGI; my $upload_dir = "uploads"; #permissions for dir are set print $query->header(); if($ENV{CONTENT_LENGTH} > $maxsize){ print "file too large - must be less than $maxsize bytes"; exit; } my $file = $query->param("file"); my $filename = $file; $filename =~s/.*[\/\\](.*)/$1/; open (UPLOADFILE, ">$upload_dir/$filename"); $/= \8192; # sets 8192 byte buffer chunks, perldoc perlvar while ( <$file> ){ print UPLOADFILE $_; #select(undef,undef,undef,.05); #for testing } close UPLOADFILE; print <<END_HTML; <HTML> <HEAD> <TITLE>Thanks!</TITLE> </HEAD> <BODY bgcolor="#ffffff"><br> <P>Thanks for uploading file : $filename!</P> </BODY> </HTML> END_HTML

    I'm not really a human, but I play one on earth. flash japh
Re: How to upload file without using FTP?
by roboticus (Chancellor) on May 24, 2006 at 11:39 UTC
    madtoperl:

    A couple of things: First, in the code you've shown, you've forgotten to set $upload_dir, so your open may be failing because of that. Secondly, your regular expression is missing a character. I think you meant this:

    s/([^\/\\]+)$//;
    But after seeing what you're doing, I'd simplify and rearrange the filename parsing bit to look like this:

    my ($drive, $path, $file); die "Invalid file name!" unless $file_query1 =~ /(\w:)?(.+)[\\\/](.*)/; print "Drive=", $1, ", Path=", $2, ", File=", $3, "\n";
    In any case, I'd second McDarren's suggestion. I've used Net::FTP and it works nicely for jobs like this.

    --roboticus

Re: How to upload file without using FTP?
by arkturuz (Curate) on May 24, 2006 at 09:12 UTC
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: How to upload file without using FTP?
by TedPride (Priest) on May 24, 2006 at 17:18 UTC
    Net::FTP (which comes with the standard Perl installation) will make this a whole lot simpler. Just install Perl on your comp, and use something like the following:
    use strict; use warnings; use Net::FTP; my ($ftp, $host, $user, $pass, $dir, $fpath); $host = "ftp.host.com"; $user = "myuser"; $pass = "mypass"; $dir = "/www/htdocs"; $fpath = "D:\work for people\k****ij\oil1.shtml"; $ftp = Net::FTP->new($host, Debug => 0); $ftp->login($user, $pass) || die "Bad login"; $ftp->cwd($dir) || die "Unable to change directories"; $ftp->put($fpath) || die "Unable to upload file"; $ftp->quit; print "Success!";
    Then if you don't want to have to run even this manually, set up an automatic job to call perl myscriptpath.pl every so often.
Re: How to upload file without using FTP?
by hossman (Prior) on Oct 08, 2006 at 20:53 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://551303]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-03-19 10:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found