sub upload { use strict; use warnings; use 5.010; use Net::FTP; use Path::Class; use Prompt::Timeout; use constant TIMEOUT => 5; my ( $rvars, $rftp ) = @_; my %vars = %$rvars; # prelims for server...see if we're able to do anything my $target = "/pages/eh5v.files"; $rftp->binary or die "binary failed$!\n"; #necessary for size request $rftp->cwd($target) or warn "cwd failed in main $!\n"; my $rlist = $rftp->ls(); say "remote list is @$rlist"; # filter binaries for filetypes my @filetypes = qw/jpg jpeg png ogv mp4 m4v webm/; my $pattern = join '|', @filetypes; opendir my $eh, $vars{"to_vids"} or warn "can't open vids $!\n"; while ( readdir($eh) ) { next if /~$/ || -d || !/$pattern/i; my $full_path = file( $vars{"to_vids"}, $_ ); my $string_path = $full_path->stringify; my $size_local = -s $string_path; say "value for $_ is $size_local"; #find size on server my $size_remote = $rftp->size($_) or warn "size query undef for $_\n"; if ( defined($size_remote) ) { say "size remote for $_ is $size_remote" } else { say "$_ doesn't exist" } ## control for upload cases if ( defined($size_remote) ) { my $default = ( $size_remote == $size_local ) ? 'N' : 'Y'; my $answer = prompt( 'Overwrite?', $default, TIMEOUT ); ftp_binary( $string_path, $_, $rftp, $target ) if $answer =~ /^Y/i; # overwrite } else { ftp_binary( $string_path, $_, $rftp, $target ); } } closedir $eh; # make new directory for page's specific images my $path5 = dir( "", "images", $vars{remote_dir} ); my $string_path5 = $path5->stringify; say "string path5 is $string_path5"; my $mk_return = $rftp->mkdir($string_path5) or warn "mkdir failed in upload $!\n"; say "mk_return is $mk_return"; ######### this part is clunky my $refc = $vars{"ref_content"}; my @AoA = @$refc; for my $i ( 0 .. $#AoA ) { my $a = file( $vars{to_images}, $AoA[$i][0] ); my $sa = $a->stringify; my $b = file( $AoA[$i][0] ); my $sb = $b->stringify; ftp_binary( $sa, $sb, $rftp, $string_path5 ); } #load css file to server my $path3 = file( $vars{"template_path"}, $vars{"css_file"} ); my $string_path3 = $path3->stringify; my $css_return = ftp_ascii( $string_path3, $vars{"css_file"}, $rftp, "/css" ) or warn "put failed $@\n"; say "css return was $css_return"; #load html file to server my $path4 = file( $vars{"base_path"}, $vars{"html_file"} ); my $string_html = $path4->stringify; my $html_return = ftp_ascii( $string_html, $vars{"html_file"}, $rftp, "/pages" ) or warn "put failed $@\n"; return $html_return; }