in reply to Re^19: transfer a file via SFTP
in thread transfer a file via SFTP

sorry to disturb u again, but I have 2 problems:

1.) I don't know howto move setup of the sftp connection outside the loop.

2.) to die if the *.txt file is not there, I tried to add these lines:
chdir "/srv" or die "/srv: $!\n"; -f "/srv/*.txt" or die "NO FILE NO TRANSFER !\n";
but it doesn't work.

greeings cc

Replies are listed 'Best First'.
Re^21: transfer a file via SFTP
by ig (Vicar) on Aug 06, 2009 at 19:51 UTC

    "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); }