Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Hi there Monks!

I am trying to delete all files from the server once downloading is completed.
My question is if this example is the best way:
# Delete a file on the server: my $success = $sftp->RemoveFile("test.txt"); if ($success != 1) { print $sftp->lastErrorText() . "\n"; exit; } print "Files Deleted!" . "\n";
This is more of the code I am using:
... # For debugging purposes you can run ssh in verbose mode passing it +the -v option: my $sftp = new Net::SFTP::Foreign(host => $host, user=>$user, passwo +rd=>$pwd, more => '-v'); $sftp->die_on_error("unable to connect to remote host"); $sftp->setcwd('/directory') or die "unable to change cwd: " . $sftp- +>error; print $sftp->cwd . "\n"; my $files = $sftp->ls('/directory', no_wanted => qr/^\./); # get files now $sftp->mget('*.txt', "/in_dir", no_wanted => qr/^\./, numbered => 1) + or die "mget failed: " . $sftp->error; #print "$_->{filename}\n" for @$files; #print "$_->{longname}\n" for @$files; my @all_files; foreach my $files (@$files) { next unless ($files->{filename} =~ m/\.txt$/); push @all_files, $files->{filename}; } if ( !$@ ) { print "\n Transmission complete...\n"; # Delete a file on the server: my $success = $sftp->RemoveFile("test.txt"); if ($success != 1) { print $sftp->lastErrorText() . "\n"; exit; } print "Files Deleted!" . "\n"; }else { print "\n File download failed, try later.\n"; } $sftp->disconnect; do_other_stuff(\@all_files); ...
Thanks for the Help!

In reply to Delete files from server after downloading using SFTP by Anonymous Monk

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (14)
    As of 2014-07-25 10:03 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (170 votes), past polls