"it doesn't work" is a bit too vague for me to be able to help you. What happens? Are any messages produced?

You need to learn some basic programming and debugging skills. For the former I suggest How to Design Programs or, if that doesn't suite you, find something in Where and how to start learning Perl that does or enroll in an introductory programming course. For the latter, you might find the advice in brian's Guide to Solving Any Perl Problem helpful.

The -f test doesn't do glob matching on the file name. Your test would only succeed if there were a file named, literally, "/srv/*.txt". Try something like the following:

my $dir = '/srv'; chdir $dir or die "$dir: $!"; my $sftp=Net::SFTP->new($server, %args) or die "could not open connection to $server\n"; my @files = glob('*.txt'); die 'No files to transfer' unless(@files); foreach my $file (@files) { $sftp->put($file, "/HOME/$file") or die; sleep(5); }

In reply to Re^21: transfer a file via SFTP by ig
in thread transfer a file via SFTP 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.