Friday I had some troubles about how to detect tar files in use, which are uploaded to the box with FTP. I had lots of input from monks here, al'do I did not realize any of they suggestions, they did give me an idea how to solve my problem. TAR does not give any output if extraction is successful, at least none that I know. So I thought about putting that in the variable and use that one. Unfortunately it does not work so good. Can you, perlmonks, take a look and enlighten my path ?




#! /usr/bin/perl -w
use Net::FTP;
use File::Copy;
my $sfile = "data*.tar"
my $dstftp = "1.1.1.1"
chomp(my @files=`ls $sfile`);
foreach $files (@files) {
        copy("$files","work/$files") or die "Copy failed: $!";
        my $testit = exec "cd work/ ;tar xf $files ; cd ..";
        if ($testit == undef)
                {
                chomp(my @lpfiles = `ls work/data_10*`);
                foreach $lpfiles(@lpfiles) {
                        $ftp = Net::FTP->new("$dstftp", Debug => 1)
                                or die "Cannot connect to host: $@\n";
                        $ftp->login("user",'passwd')
                                or die "Cannot login \n ", $ftp->message;
                        $ftp->binary or die ("cant Binary \n");
                        $ftp->hash or die ("cant Hash \n");
                        $ftp->cwd("test/")
                                or die "Cannot change working directory \n", $ftp->message;
                        $ftp->put("work/$lpfiles")
                                or die "put failed \n", $ftp->message;
                        $ftp->quit;
                        move("work/$lpfiles","/dev/null");                     
                        }
                        move("$files","/dev/null");
               }
                else {
                	print "Nothing to do. No readable TAR files"
        }
}

In reply to Working with TAR files by SpaceCake

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.