Here is a little Tk script that will upload a file to a specific cgi program you run on your server. It has a progressbar and text output for stderr messages. You can modify it to use basic auth if desired, or have specific passwords for each user. (just add a form field to the upload)
#!/usr/bin/perl use warnings; use strict; use HTTP::Request::Common qw(POST); use LWP::UserAgent; use Tk; require Tk::ProgressBar; my $file = shift || 'z.mpg'; my $url = 'http://zentara.zentara.net/~zentara/cgi-bin/up1.cgi'; my $progress = 0; my $cancel = 0; $|++; my $mw = MainWindow->new; my $tframe = $mw->Frame( -background => 'grey45' )->pack( -fill => 'x' ); $tframe->Label( -background => 'black', -foreground => 'green', -width => 4, -textvariable => \$progress, )->pack(-side =>'left'); $tframe->Label( -background => 'black', -foreground => 'green', -text => '%', )->pack(-side =>'left'); my $pb = $tframe->ProgressBar( -length => 500, -width => 20, -from => 0, -to => 100, -blocks => 100, -colors => [ 0, 'green', 50, 'lightblue', 80, 'yellow' ], )->pack(-padx => 10); my $text = $mw->Scrolled("Text", -height => 20, -background => 'black', -foreground => 'yellow', )->pack( -expand => 1, -fill => 'both' ); my $bframe = $mw->Frame( -background => 'grey45' )->pack( -fill => 'x' ); my $button; $button = $bframe->Button( -text => 'Start Upload', -background => 'lightgreen', -command => sub { if($button->cget('-text') eq 'Start Upload'){ $button->configure(-text => 'Cancel', -background => 'hotpink'); $cancel = 0; &upload_it( $url, $file ); }else{ $button->configure(-text => 'Start Upload', -background => 'lightgreen'); $cancel = 1; } })->pack(-side => 'left', -padx => 20); $bframe->Button( -text => 'Exit', -background => 'Red', -command => sub { $pb->destroy; exit; } )->pack(-side =>'right',-padx => 20); MainLoop; ############################################################3 sub upload_it() { my ( $url , $file) = @_; my $size = -s $file; my $tot = 0; $pb->value(0); $progress = 0; my $start = time; my $starttime = scalar localtime; my $message = "\n\n\nUploading $file , size $size to\n$url\n at $starttime\n "; $text->insert('end', $message); $text->see('end'); $HTTP::Request::Common::DYNAMIC_FILE_UPLOAD = 1; my $ua = new LWP::UserAgent; my $req = POST $url, Content_Type => 'multipart/form-data', Content => [ file => [$file] ]; my $gen = $req->content(); die unless ref($gen) eq "CODE"; $req->content( sub { my $chunk = &$gen(); if (defined $chunk){ $tot += length($chunk) } $progress = int(($tot/$size) *100); if($cancel){goto END} $pb->value($progress); $mw->update; return $chunk; } ); my $res = $ua->request($req); #do it if ( $res->is_success ) { $text->insert('end', $res->as_string); } else { $text->insert('end',$res->status_line); } END: my $condition = 'Finished'; if($cancel){ $condition = 'CANCELLED'; $cancel = 0; } my $diff = time - $start; my $endtime = scalar localtime; $message = "$condition $file, at $endtime total time = $diff seconds\n\n\n " +; $text->insert('end', $message); $text->see('end'); $button->configure(-text => 'Start Upload', -background => 'lightgreen'); undef $ua; }

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

In reply to Re: how can i upload a file to my webserver by zentara
in thread how can i upload a file to my webserver by koleti

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.