Aldebaran has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I've been rather ambitious with perl projects lately, porting my html template from a linux laptop to a windows 8.1 laptop with a cygwin installation. I was stunned with how little resistance I encountered, but I do have a couple problems. First, I'd like to address the main topic of this post, which is creating a sensible control for uploading binary content to my site. Let me show you what I have but preface it by saying that I'm without perltidy at the moment (see question 2).
sub upload { use strict; use warnings; use 5.010; use Net::FTP; use Data::Dumper; my ($rvars, $rftp) = @_; my %vars = %$rvars; # get local files into an array my @filetypes = qw/jpg jpeg png ogv mp4 m4v webm/; my $pattern = join '|', map "($_)", @filetypes; my @matching; opendir my $eh, $vars{"to_vids"} or warn "can't open vids $!\n"; while (defined ($_ = readdir($eh))){ next if m/~$/; next if -d; if ($_ =~ /($pattern)$/i) { push(@matching, $_); } } closedir $eh; # stat local files, create hash #my %stat = map { # lstat($_) or die "Can't lstat $_: $!"; # $_ => { # s => ( -s _ ), # } #} @matching; #my $hashref = \%stat; #print Dumper($hashref); $rftp->cwd("/pages/eh5v.files") or warn "cwd failed in main $!\n"; my $rlist = $rftp->ls(); say "list is @$rlist"; $rftp->binary or warn "binary failed$!\n"; for ( @matching) { #say "matching is @matching"; my $a = file($vars{"to_vids"},$_); my $sa = $a->stringify; #$rftp->put($sa, $_) or warn "put failed $@\n"; } $rftp->ls(); return $rftp; }
The relevant part of the output is:
loading vids list is . .. kitchen.jpg kitchen.m4v kitchen.webm stairs.jpg stairs.m4 +v
What am I trying to do? I want a control to loop through the above files, and first see whether it exists on the remote server. If not, we upload it. If yes, then I'm interested in whether they are either a differing size or creation date. That's what the commented lstat part was to address, but I got errors out of that, because I didn't build the full path. (I think.) If they are different, I want a prompt to overwrite with the default being yes. If they are not different, then I want a prompt to overwrite with the default being no. It would be cool if this could work on a five-second timer. Furthermore, I would like not to create race conditions. And finally, I'd like to have a portion of code to deal with error handling such as time-outs, or directory doesn't exist. The directory, of course "should" exist, but that's one of those words....
So that's very ambitious, and I'm not completely-wed to any part of the spec if it's ill-advised, but I thought I'd throw the whole thing out there in the original post. If I get it right once, it's eminently re-usable.
I have 2 other questions that are unrelated to the above. I don't think they deserve their own threads. To the extent that a subthread lasts more than one level, maybe we can rename it appropriately. How do I get CPAN to kickstart?
$ perl -MCPAN -e shell Set up gcc environment - 3.4.5 (mingw-vista special r3) cpan shell -- CPAN exploration and modules installation (v1.9800) Enter 'h' for help.
This hangs. I'm running the 64-bit cygwin download that is no more than 2 weeks old on a 64-bit windows 8.1 machine. Do I have cpan and not know it? I don't think so:
Fred@Psiborg ~/pages2/krov $ sudo cpan -bash: sudo: command not found Fred@Psiborg ~/pages2/krov $ cpan -bash: cpan: command not found Fred@Psiborg ~/pages2/krov $ cpan My :: Module -bash: cpan: command not found Fred@Psiborg ~/pages2/krov $
Finally, I reached the level of Scribe recently, and I think it would behoove me to have a better brand name. To this end, I'd like to change my username to something cooler and more-identifiable than my current one, which is just an arbitrary 'nym. How do I do that?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: a full-featured control for uploading files and a couple of other tidbits
by Athanasius (Archbishop) on May 23, 2015 at 07:50 UTC | |
|
Re: a full-featured control for uploading files
by Aldebaran (Curate) on May 24, 2015 at 00:25 UTC | |
by Athanasius (Archbishop) on May 24, 2015 at 06:38 UTC | |
by Aldebaran (Curate) on May 26, 2015 at 07:59 UTC |