hi

I have this perl script:
#!/usr/bin/perl -w use strict; use warnings; use File::Copy; use Net::SFTP; use Mail::Sender; my $server = "myserver"; my $user = "user"; my %args = (ssh_args => []); $args{debug} = 1; $args{user} = "user"; # ftp directories my $remote_directory_1 = ""; my $recipient = "it\@mydomain.net"; my $linux = "root\@mydomain.net"; # write the log BEGIN { use CGI::Carp qw(carpout); my $errorlog = "/srv/ftp/data/logs/errorlog.txt"; open(LOG, ">$errorlog") or die("Unable to open $errorlog: $!\n"); print LOG "Errors:\n"; carpout(*LOG); } chdir "/srv/ftp/data/IN" or die "/srv/ftp/data/IN: $!\n"; -f "/srv/ftp/data/IN/INFO" or die "NO INFO NO TRANSFER !\n"; my @ftp_locations = $remote_directory_1; # open the file safely or complain it wouldn't open open(FILE, "<", "INFO") or die "Failed to open info file: $!"; # read all the lines in from INFO my @files; for(my $i = 1; $i <= @ftp_locations; $i++) { $_ = <FILE>; s/\W*$//; # remove trailing whitespace next if (!$_); # skip empty lines # check that we get our match. If not, # complain and move on. Want to see two # filenames. unless(/^([\w.-]+) \s+ ([\w.-]+)$/x) { print STDERR "$_ is not a valid line"; next; } # rename the files as per rename in file my ($old, $new) = ($1, $2); unless( -e $old ) { print STDERR "$old does not exist!\n"; next; } rename $old, $new; push @files, $new; } # check that we have the number of files that we expect unless(@files == @ftp_locations) { die "Not enough specified ftp_locations for ". "given number of files!"; } # create backup subfolder my @dt = localtime; my $subfolder_name = ((((1900 + $dt[5]) * 100 + 1 + $dt[4]) * 100 + $d +t[3]) * 100 + $dt[2]) * 100 + $dt[1]; mkdir "/srv/ftp/data/OUT/$subfolder_name" or die "$subfolder_name: $!" +; # FTP each file across, die on errors foreach my $new (@files) { my $destination = shift @ftp_locations; # sftp transfer my $sftp=Net::SFTP->new($server, %args) or die "could not open + connection to $server\n"; # change remote directory for the first file # $sftp->cd($destination); # $sftp->binary; $sftp->put($new, $new) or die "could not upload a file\n"; #quit SFTP When finished #$sftp->quit; # move files to backup directory unless(move("$new", "/srv/ftp/data/OUT/$subfolder_name")) { print STDERR "Oops! Couldn't move the file: $!"; } move "/srv/ftp/data/IN/INFO", "/srv/ftp/data/OUT/$subfolder_name"; move "/srv/ftp/data/logs/errorlog.txt", "/srv/ftp/data/OUT/$subfolder_ +name"; sleep (1 * 5) } close(FILE); # read the log file my $content; open(FILE2, "/srv/ftp/data/OUT/$subfolder_name/errorlog.txt") || die " +Cant open file. Reason: $!"; # (-: while(<FILE2>) { $content .=$_; # get all of the file into content including past new l +ines } close(FILE2); # send a mail when transfer completed my $mail = new Mail::Sender (smtp => 'localhost', from => $linux, to => $recipient, subject => 'data transfer', msg => $content); close(LOG); exit (0);
I'm getting 2 files: one INFO and one data file.
data file should be renamed according to the INFO file and send via SFTP to the remote server.
after transfer, a new direcory will be created and the file backuped.
it works, but I don't get any mails when transfer was successfully.
I should get a content of the log file by mail.
what's wrong and howto solve this problem ?

In reply to problem with sending a file's content using Mail::Sender by cc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.