I am trying to use Net::FTP::Recursive to unzip an Archive file (.zip) and
recursively transfer the directory created to an FTP server. The problem is
that my code gives no error messages but the directory is not transferred. The
user I am running this program as is able to create directories when using
interactive FTP. Also, my code that uses the rget() method of the same module
works just fine.
It's just that I cannot get the rput() method to work.
Code is below.
Thanks in advance, sivak1976
#!/usr/bin/perl
# Program to recursively put a directory on to an FTP server
# after unzipping a Zip file.
use strict;
use warnings;
use Net::FTP::Recursive;
use Archive::Zip;
# FTP host server
my $host = 'myhost.mydomain.com';
my $zip_file_to_put = 'ABC.zip';
# Get the zip archive.
my $zip_file_obj = Archive::Zip->new($zip_file_to_put)
or die("Could not get zip file: $!");
# Extract the zip files.
$zip_file_obj->extractTree();
chdir('ABC') or die("Could not change directory: $!");
# my $current_dir = `pwd`;
# print $current_dir, "\n";
my $ftp_obj = Net::FTP::Recursive->new($host, Passive => 1)
or die "Cannot connect to $host: $!" ;
# Log in to the FTP server.
$ftp_obj->login('username', 'password') or die "Cannot log in to $host
+: $!" , $ftp_obj->message();
# Go into binary mode for the transfer
my $type = $ftp_obj->binary();
# Put the directory in a recursive fashion.
my $output = $ftp_obj->rput();
# Print the error messages if the recursive put failed.
if($output) {
print qq<rput failed, \$output was:\n$output>;
}
# Quit!
$ftp_obj->quit();
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.