end0tknr's kipple - web写経開発

太宰府天満宮の狛犬って、妙にカワイイ

SMB::Client for perl で、SMB接続し、fileをdownload

http://search.cpan.org/perldoc?SMB

https://metacpan.org/pod/SMB

上記を参考に、次のように書きます。

use strict;
use warnings;
use SMB::Client;
use Data::Dumper;

main();

sub main {
    my $client = SMB::Client->new('//192.168.56.101/end0tknr',
                                  username => 'ないしょ',
                                  password => 'ないしょ');
    my $tree = $client->connect_tree;
    
    for my $file ($tree->find("tmp/*")) {
        printf "%-40s %s\n", $file->name, $file->mtime_string;
        if($file->name eq "COPYING.txt"){
            $tree->dnload("tmp/COPYING.txt") or die "Failed to download";
        }

#        $tree->rename("my.log", $new_filename) or die "Failed to rotate";
#        $tree->dnload('new_'$new_filename) or die "Failed to download";
#        $tree->remove($new_filename) or die "Failed to remove";
    }
}