Re: [Ssh-sftp-perl-users] Put Issues with SFTP
Brought to you by:
dbrobins
|
From: Thierry C. <thi...@gm...> - 2010-12-31 09:38:22
|
Le 30/12/2010 22:31, Scott Burks a écrit :
>
> I have a perl script that logs into a vendor site and successfully
> lists the directory. But when I add the functionality to ‘put’ a
> group of files, I get the following error:
>
> “Couldn't get handle: Failure at ./blackdiamond.pl line XXX”
>
> I’ve tried ‘put’ting the file from a loop and even hard-coating for a
> specific file and get the same error. But a manual sftp and put works
> just fine.
>
> I include the snippet of script below in hopes that someone can help
> me get past this error:
>
> #!/usr/bin/perl -w
>
> use warnings;
>
> use Net::SFTP;
>
> my $putdir = "/home/blackd/put";
>
> my $server="remoteftpsite";
>
> my $username="username";
>
> my $password="password";
>
> my $sshport="220";
>
> # execute ftps to Vendor
>
> while(true) {
>
> #Get all the files in the directory
>
> @files = <$putdir/*>;
>
> #If it's empty, ignore doing anything.
>
> if(@files) {
>
> # Set up a SFTP connection and login.
>
> my $sftp = new Net::SFTP( $server, user=>$username,
> password=>$password, debug=>'true', ssh_args => [ port => '220' ] ) or
> die "Cannot Open Connection to $server";
>
> # Loop through the files found.
>
> foreach(@files) {
>
> # SFTP the files first
>
> $sftp->put($_, ".") or die "Cannot putfile";
>
> }
>
> }
>
> }
>
> closedir(PUTDIR);
>
> $sftp->ls('.' , sub { print $_[0]->{filename}, "\n" });
>
> undef $sftp;
>
> Thanks for any input,
>
Hello Scott.
I have more questions than answers, at this point.
- What line number is XXXX ?
- Why is there a while loop ? If your script work, it could overload
your ssh server.
- You seem confident that @files contains real files, but I think you
should test it before
you try to put it on the remote server.
|