App-Smbxfer
view release on metacpan or search on metacpan
lib/App/Smbxfer.pm view on Meta::CPAN
SMB_OBJ => $smb,
SOURCE => $local_src . '/' . $local_dir_elem,
SMB_PATH_SPEC => $smb_path_spec . '/' . $src_basename,
RECURSIVE => 1
);
}
closedir( $local_dir );
}
elsif( -f $local_src ) {
# Upload file...
if( $elem_type == SMBC_FILE ) {
# Destination is an existing file; remove file remotely...
$smb->unlink( $smb_path_spec )
or croak "SMB error: cannot unlink: $!";
}
elsif( $elem_type == SMBC_DIR ) {
# Destination is an existing dir => file goes inside it...
$smb_path_spec .= '/' . $src_basename;
}
open( my $sourcefile, '<', $local_src )
or croak "cannot open file: $!";
my $smb_fd = $smb->open('>' . $smb_path_spec, '0777')
or croak "SMB error: cannot create file: $!";
$smb->write( $smb_fd, $_ ) while( <$sourcefile> );
$smb->close( $smb_fd );
close( $sourcefile );
}
else {
warn "$local_src is not a directory or a file...ignoring.\n";
}
return 1;
}
#########################
1;
__END__
=pod
=head1 NAME
App::Smbxfer - A "modulino" (module/program hybrid) for file
transfer between Samba shares and the local filesystem.
=head1 MODULINO: MOTIVATION AND DESCRIPTION
This software provides a subset of the features of smbclient. The main
motivation for its existence was a limitation in smbclient causing a timeout
that precluded transfer of large files.
An especially useful way to apply this modulino is to invoke it as a
non-interactive command-line tool. This can be an effective way to create cron
jobs for backup of data TO Samba shares.
As a module, it provides functions to conduct file transfers, get information on
Samba filesystem objects, and to perform validations on "SMB path specs," Samba
location identifiers of the form:
smb://server/share/path/to/something
=head1 VERSION
This documentation refers to App::Smbxfer version 0.01.
=head1 MODULE: FUNCTIONS
Functions in App::Smbxfer are used to aid with transferring files between Samba
shares and the local filesysem. This is the context in which the following
functions are provided.
=head2 usage
Prints command-line usage information.
=head2 options
Prints command-line options.
=head2 run
"main() method" for running module as a command-line program.
=head2 credentials
my ($username, $password, $domain) = credentials( $credentials_file );
Load SMB access credentials from the specified filename, which should be
formatted as expected by the smb* suite of tools (smbclient, etc.)
=head2 validated_paths
my ($local_path, $remote_smb_path_spec) = validated_paths(
SMB => $smb,
SOURCE => $source,
DEST => $dest,
SOURCE_IS_LOCAL => $whether_or_not_source_is_local_path
);
Given source, destination paths as expected by modulino's run()
function, performs validations and returns normalized forms of both paths in
order (source, dest).
=head2 do_smb_transfer
do_smb_transfer(
SMB_OBJECT => $smb,
LOCAL_PATH => $local_path,
SMB_PATH_SPEC => $remote_smb_path_spec,
SOURCE_IS_LOCAL => $whether_or_not_source_is_local_path,
RECURSIVE => 1,
CREATE_PARENTS => 1
( run in 0.674 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )