view release on metacpan or search on metacpan
lib/App/Followme/UploadFtp.pm view on Meta::CPAN
$status = 1;
}
return 1;
}
#----------------------------------------------------------------------
# Open the connection to the remote site
sub open {
my ($self, $user, $password) = @_;
# Open the ftp connection
my $ftp = Net::FTP->new($self->{ftp_url}, Debug => $self->{ftp_debug})
or die "Cannot connect to $self->{ftp_url}: $@";
$ftp->login($user, $password) or die "Cannot login ", $ftp->message;
$ftp->cwd($self->{remote_directory})
or die "Cannot change remote directory ", $ftp->message;
$ftp->binary();
$self->{ftp} = $ftp;
$self->{ascii} = 0;
return;
lib/App/Followme/UploadFtp.pm view on Meta::CPAN
__END__
=encoding utf-8
=head1 NAME
App::Followme::UploadFtp - Upload files using ftp
=head1 SYNOPSIS
my $ftp = App::Followme::UploadNone->new(\%configuration);
$ftp->open($user, $password);
$ftp->add_directory($dir);
$ftp->add_file($local_filename, $remote_filename);
$ftp->delete_file($filename);
$ftp->delete_dir($dir);
$ftp->close();
=head1 DESCRIPTION
L<App::Followme::UploadSite> splits off methods that do the actual uploading
into a separate package, so it can support more than one method. This package
lib/App/Followme/UploadFtp.pm view on Meta::CPAN
=item $self->close();
Close the ftp connection to the remote site.
=back
=head1 CONFIGURATION
The follow parameters are used from the configuration. In addition, the package
will prompt for and save the user name and password.
=over 4
=item ftp_debug
Set to one to trace the ftp commands issued. Useful to diagnose problems
with ftp uploads. The default value is zero.
=item remote_directory
lib/App/Followme/UploadLocal.pm view on Meta::CPAN
my $new_file = catfile($self->{remote_directory}, $filename);
my $status = unlink($new_file);
return $status;
}
#----------------------------------------------------------------------
# Open the connection to the remote site
sub open {
my ($self, $user, $password) = @_;
# Check existence of remote directory
my $found = $self->{remote_directory} && -e $self->{remote_directory};
die "Could not find remote_directory: $self->{remote_directory}"
unless $found;
return;
}
lib/App/Followme/UploadNone.pm view on Meta::CPAN
sub delete_file {
my ($self, $filename) = @_;
return 1;
}
#----------------------------------------------------------------------
# Open the connection to the remote site
sub open {
my ($self, $user, $password) = @_;
return;
}
1;
__END__
=encoding utf-8
=head1 NAME
App::Followme::UploadNone - Go through the motions of uploading files
=head1 SYNOPSIS
my $uploader = App::Followme::UploadNone->new(\%configuration);
$uploader->open($user, $password);
$uploader->add_directory($dir);
$uploader->add_file($local_filename, $remote_filename);
$uploader->delete_directory($dir);
$uploader->delete_file($filename);
$uploader->close();
=head1 DESCRIPTION
L<App::Followme::UploadSite> splits off methods that do the actual uploading
into a separate package, so it can support more than one method. This is the
lib/App/Followme/UploadNone.pm view on Meta::CPAN
Close the connection to the remote site.
=item $flag = $self->delete_directory($dir);
Delete a directory, including any files it might hold.
=item $flag = $self->delete_file($filename);
Delete a file on the remote site.
=item $self->open($user, $password);
Open the connection to the remote site
=item $self->setup();
Set up computed fields in the new object
=back
=head1 LICENSE
lib/App/Followme/UploadSite.pm view on Meta::CPAN
};
my $error = $@;
$self->write_hash_file($hash);
die $error if $error;
return;
}
#----------------------------------------------------------------------
# ASK_WORD -- Ask for user name and password if file not found
sub ask_word {
my ($self) = @_;
print "\nUser name: ";
my $user = <STDIN>;
chomp ($user);
print "Password: ";
my $pass = <STDIN>;
lib/App/Followme/UploadSite.pm view on Meta::CPAN
die "Bad line in hash file: ($name)" unless defined $value;
$hash{$name} = $value;
}
}
return \%hash;
}
#----------------------------------------------------------------------
# Read the user name and password from a file
sub read_word {
my ($self, $filename) = @_;
my $obstr = fio_read_page($filename) || die "Cannot read $filename\n";
chomp($obstr);
my ($user, $pass) = $self->unobfuscate($obstr);
return ($user, $pass);
}
lib/App/Followme/UploadSite.pm view on Meta::CPAN
later then the last time it was run are checked.
=head1 CONFIGURATION
The following fields in the configuration file are used:
=over 4
=item credentials
The name of the file which holds the user name and password for the remote site
in obfuscated form. Te default name is 'upload.cred'.
=item hash_file
The name of the file containing all the checksums for files on the site. The
default name is 'upload.hash'.
=item max_errors
The number of upload errors the module tolerate before quitting. The default
t/UploadFtp.t view on Meta::CPAN
remote_pkg => 'File::Spec::Unix',
);
#----------------------------------------------------------------------
# Test
SKIP: {
# Site specific configuration
my $user = '';
my $password = '';
$configuration{ftp_url} = '';
$configuration{remote_directory} = '';
skip('Ftp connection not configured', 5) unless $configuration{ftp_url};
# Test files
my $dir = 'subdir';
my $remote_file = 'filename.html';
my $local_file = catfile($test_dir, $remote_file);
t/UploadFtp.t view on Meta::CPAN
EOQ
my $fd = IO::File->new($local_file, 'w');
print $fd $file;
close($fd);
# The methods to test
my $up = App::Followme::UploadFtp->new(%configuration);
$up->open($user, $password);
my $flag =$up->add_directory($dir);
is($flag, 1, 'Add directory'); # test 1
$flag = $up->add_file($local_file, $remote_file);
is($flag, 1, 'Add file'); # test 2
$flag = $up->add_file($local_file, $remote_file);
is($flag, 1, 'Add file again'); # test 3
$flag = $up->delete_file($remote_file);
t/UploadNone.t view on Meta::CPAN
top_directory => $test_dir,
);
#----------------------------------------------------------------------
# Test
do {
my $up = App::Followme::UploadNone->new(%configuration);
my $user = 'user';
my $password = 'password';
my $dir = 'subdir';
my $remote_file = 'filename';
my $local_file = catfile($dir, $remote_file);
$up->open($user, $password);
my $flag =$up->add_directory($dir);
is($flag, 1, 'Mock add directory'); # test 1
$flag = $up->add_file($local_file, $remote_file);
is($flag, 1, 'Mock add file'); # test 2
$flag = $up->delete_directory($dir);
is($flag, 1, 'Mock delete directory'); # test 3
$flag = $up->delete_file($remote_file);
t/UploadSite.t view on Meta::CPAN
upload_pkg => 'App::Followme::UploadLocal',
);
#----------------------------------------------------------------------
# Test read and write files
do {
my $up = App::Followme::UploadSite->new(%configuration);
my $user_ok = 'gandalf';
my $password_ok = 'wizzard';
my $cred_file = catfile(
$up->{top_directory},
$up->{state_directory},
$up->{credentials},
);
$up->write_word($cred_file, $user_ok, $password_ok);
my ($user, $pass) = $up->read_word($cred_file);
is($user, $user_ok, 'Read user name'); # test 1
is($pass, $password_ok, 'Read password'); # test 2
my $hash_file = catfile($up->{top_directory},
$up->{state_directory},
$up->{hash_file});
my $hash_ok = {'file1.html' => '014e32',
'file2.html' => 'a31571',
'sub' => 'dir',
'sub/file3.html' => '342611'
};