lundi 28 septembre 2015

Fetch and upload files and prefixed files to s3 using perl

I am trying to fetch files from s3 using Amazon::S3 module in Perl . I am successfully able to download files which are not prefixed but unable to fetch prefixed files like test/abc.txt.

I am using below code.

sub export_bucket {
  my ($conn, $bucket, $directory) = @_;
  $bucket = $conn->bucket($bucket);
  my $response = $bucket->list();
  print $response->{bucket}."\n";
  for my $key (@{ $response->{keys} }) {
        print "\t".$key->{key}."\n";  
        _export_file($conn,$bucket,$key->{key}, $directory.'/'.$key->{key});
  }
}

sub _export_file {
  my ($conn,$bucket,$name,$path) = @_;
  print "Downloading $name file","\n";
  my $test = $bucket->get_key_filename($name,'GET',$path);
  print Dumper($test);
  my $acl = $bucket->get_acl($name);
  print Dumper($acl);
  open my $acl_file, '>', $path.'.acl';
  print $acl_file $acl;
  close $acl_file;
}

Suggest me what changes should i make so that when a prefixed/folder comes i should be able to download the folder as well.

Thanks




Aucun commentaire:

Enregistrer un commentaire