"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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |