#!/usr/bin/perl -w use Net::FTP; use strict; use warnings; # FTP Login information and paths to various locations, local then remote my ($uid, $pwd, $ld, $rd) = @ARGV; # FTP address my $ftp_url = "ftp.photobucket.com"; # Cleans up the local path to work better with Perl on Windows. # Untested on *nix systems. my $triml = length($ld); if (substr($ld, length($ld), 1) ne "/") { $ld .= "/"; $triml++; } my $fixed_ld = $ld; $fixed_ld =~ s/\s/\\ /g; my $ftp = Net::FTP->new($ftp_url, Debug => 0) or die "Cannot connect"; $ftp->login($uid, $pwd) or die "Cannot login: " . $ftp->message; $ftp->binary(); $ftp->cwd($rd) or die "Cannot change working directory "; my @rf = $ftp->ls(); foreach my $f (<$fixed_ld*>) { my $temp = substr($f, $triml); my $isin = 0; if ($temp eq "." || $temp eq ".." || -d $f || $temp !~ m/\.(png|jpg|gif|bmp)/i) { next; } foreach my $rf (@rf) { if (lc($rf) eq lc($temp)) { $isin = 1; last; } } if ($isin == 1) { next; } my $upf = $ld . $temp; unless($ftp->put($upf)) { print STDERR "Upload failed: " . $ftp->message; sleep(1) } } $ftp->quit; exit;