Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ab31bb2dc | ||
|
|
0b22e1267e | ||
|
|
c4dd3401f8 | ||
|
|
318cacd918 | ||
|
|
6541f9da75 | ||
|
|
ae03d04d15 | ||
|
|
076180f4cb | ||
|
|
111f7bcac0 | ||
|
|
bc073154e7 | ||
|
|
44d3715566 | ||
|
|
1953f7dfd9 | ||
|
|
a40e1bc0fd | ||
|
|
77f295ba56 | ||
|
|
f4b32c93da | ||
|
|
b685d21e3f | ||
|
|
034afa8b53 | ||
|
|
2d87c5392c |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
testfolder/*
|
||||
test*.txt
|
||||
13
install.sh
13
install.sh
@@ -24,9 +24,16 @@ if [ "$EUID" -ne 0 ]; then
|
||||
echo "This script must be run as root to install system-wide"
|
||||
exit 1
|
||||
fi
|
||||
cp ./transfer.pl /usr/local/bin/transfer.pl
|
||||
cp ./estimate.pl /usr/local/bin/estimate.pl
|
||||
cp ./fixlist.sh /usr/local/bin/fixlist.sh
|
||||
cp ./src/transfer.pl /usr/local/bin/transfer
|
||||
cp ./src/estimate.pl /usr/local/bin/estimate
|
||||
cp ./src/fixlist.sh /usr/local/bin/fixlist
|
||||
chmod 755 /usr/local/bin/transfer.pl
|
||||
chmod 755 /usr/local/bin/estimate.pl
|
||||
chmod 755 /usr/local/bin/fixlist.sh
|
||||
|
||||
cpan install Getopt::Long
|
||||
|
||||
if [ -z "$(echo $PATH | grep '.usr.local.bin')" ]; then
|
||||
echo "/usr/local/bin not found in your PATH."
|
||||
echo "Please add /usr/local/bin to your PATH export"
|
||||
fi
|
||||
33
man/transfer.1
Normal file
33
man/transfer.1
Normal file
@@ -0,0 +1,33 @@
|
||||
.Dd August 09, 2024
|
||||
.Os FreeBSD 14.1
|
||||
.Dt TRANSFER [1]
|
||||
.Sh NAME
|
||||
.Nm transfer
|
||||
.Nd transfer files using rsync
|
||||
.Sh SYNOPSIS
|
||||
|
||||
.Nm transfer
|
||||
.Op Fl path Ar inpath
|
||||
.Op Fl host Ar host
|
||||
.Op Fl user Ar username
|
||||
.Op Fl dest Ar outpath
|
||||
.Op Fl flags Ar rsyncflags
|
||||
.Op Fl verbose
|
||||
.Op Fl help
|
||||
.Op Fl dir
|
||||
|
||||
.Sh DESCRIPTION
|
||||
|
||||
The .Nm transfer utility takes as input a list of absolute file or directory
|
||||
paths, and transfers those files or directories and their contents to a remote
|
||||
system.
|
||||
|
||||
The following options are available:
|
||||
|
||||
.Op path
|
||||
.Bd -offset indent
|
||||
|
||||
.Sh ENVIRONMENT
|
||||
.Sh FILES
|
||||
.Sh EXAMPLES
|
||||
|
||||
150
src/transfer.pl
Executable file
150
src/transfer.pl
Executable file
@@ -0,0 +1,150 @@
|
||||
#!/usr/bin/env perl
|
||||
# Transfer script transfer.pl
|
||||
# Author: Elia Farin
|
||||
# Written: 8/9/24
|
||||
# Modified: 8/9/24
|
||||
# License: AGPL-3.0-or-later
|
||||
#
|
||||
# Copyright (C) 2024 Elia Farin
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
use strict;
|
||||
use Getopt::Long;
|
||||
|
||||
|
||||
# sane defaults
|
||||
my $path= "";
|
||||
my $host = "";
|
||||
# get running user's name
|
||||
my $user = getlogin() || (getpwuid($<))[0] || $ENV{LOGNAME} || $ENV{USER};
|
||||
my $dest= "/home/$user/Downloads/";
|
||||
my $flags = "rvz";
|
||||
my $verbose;
|
||||
my $help;
|
||||
my $dir;
|
||||
my $retries = 2;
|
||||
my $tries = 0;
|
||||
my $returncode;
|
||||
# options
|
||||
my $result = GetOptions ( "path=s" => \$path,
|
||||
"host=s" => \$host,
|
||||
"dir" => \$dir,
|
||||
"user=s" => \$user,
|
||||
"dest=s" => \$dest,
|
||||
"flags=s" => \$flags,
|
||||
"verbose" => \$verbose,
|
||||
"retries" => \$retries,
|
||||
"help" => \$help);
|
||||
|
||||
|
||||
sub transfer {
|
||||
#print "file: $file, host: $host, srcdir: $dir, user: $user, dest: $dest flags: $flags verbose: $verbose help: $help\n";
|
||||
### Begin main logic
|
||||
# help catch
|
||||
if ($help) {
|
||||
help();
|
||||
|
||||
}
|
||||
# if we're passed the directory flag and we have the required options set
|
||||
elsif ($dir && length $host && length $dest && length $user) {
|
||||
|
||||
print "Transferring object 1 of 1 \n\n";
|
||||
$tries = 0;
|
||||
# transfer our directory
|
||||
while ($tries <= $retries) {
|
||||
|
||||
$returncode = system("rsync", "-$flags", "$dir", "$user\@$host:$dest");
|
||||
if ($returncode == 0) {
|
||||
last;
|
||||
} else {
|
||||
$tries++;
|
||||
}
|
||||
}
|
||||
}
|
||||
# If we have all the right options set for an infile, begin the copy
|
||||
elsif (length $path && length $host && length $user && length $dest) {
|
||||
#print "in elsif block\n";
|
||||
# Open our filehandle
|
||||
open my $info, $path or die "Could not open $path: $!";
|
||||
|
||||
my $linesnum = 0;
|
||||
while( my $iterline = <$info>) {
|
||||
#print "in first while loop\n";
|
||||
$linesnum++;
|
||||
}
|
||||
|
||||
# wqe need to close the filehandle or we won't be able to read the file again
|
||||
close $path;
|
||||
|
||||
# open our filehandle, this time for taking action
|
||||
open $info, $path or die "Could not open $path: $!";
|
||||
my $xfernum = 0;
|
||||
# read line by line
|
||||
while( my $line = <$info> ) {
|
||||
#print "in second while loop\n";
|
||||
$xfernum++;
|
||||
chomp $line;
|
||||
$tries = 0;
|
||||
# actual copy logic
|
||||
if (length $verbose) {
|
||||
while ($tries <= $retries) {
|
||||
#print "in verbose section";
|
||||
print "\n\nTransferring object $xfernum of $linesnum\n\n";
|
||||
$returncode = system("rsync", "-vvv", "-$flags", "$line", "$user\@$host:$dest");
|
||||
if ($returncode == 0) {
|
||||
last;
|
||||
} else {
|
||||
$tries++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while ($tries <= $retries) {
|
||||
#print "in non-verbose section";
|
||||
print "\n\nTransferring object $xfernum of $linesnum\n\n";
|
||||
$returncode = system("rsync", "-$flags", "$line", "$user\@$host:$dest");
|
||||
|
||||
if ($returncode == 0) {
|
||||
last;
|
||||
} else {
|
||||
$tries++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
close $path;
|
||||
|
||||
}
|
||||
# if we fail the variables check, print usage help
|
||||
else {
|
||||
#print "In help else\n";
|
||||
help();
|
||||
}
|
||||
|
||||
# help subroutine
|
||||
sub help {
|
||||
print "Usage: $ARGV[0] --path <infile or directory> [--dir] --host <IP or DNS name> --user <username> --dest <destination path> [--flags <rsync flags>] [--verbose] [--help]\n
|
||||
--path - Input file to read or directory to copy
|
||||
--host - IP address or hostname of the remote system
|
||||
--dir - enable directory copy mode
|
||||
--user - User account on the remote system to use
|
||||
--dest - Destination on the remote system to copy files to
|
||||
--flags - rsync flags to use when copying the files over. Defaults to rvz
|
||||
--retries - number of retries on failed rsync (default 2)
|
||||
--verbose - run rsync with -vvv
|
||||
--help - show this help\n";
|
||||
}
|
||||
}
|
||||
|
||||
transfer();
|
||||
90
transfer.pl
90
transfer.pl
@@ -1,90 +0,0 @@
|
||||
#!/usr/local/bin/perl
|
||||
# Transfer script transfer.pl
|
||||
# Author: Elia Farin
|
||||
# Written: 8/9/24
|
||||
# Modified: 8/9/24
|
||||
# License: AGPL-3.0-or-later
|
||||
#
|
||||
# Copyright (C) 2024 Elia Farin
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
use strict;
|
||||
use Getopt::Long;
|
||||
use re;
|
||||
my $username = getlogin() || (getpwuid($<))[0] || $ENV{LOGNAME} || $ENV{USER};
|
||||
|
||||
# sane defaults
|
||||
my $file = "";
|
||||
my $host = "";
|
||||
my $directory = ".";
|
||||
my $user = $username;
|
||||
my $dest= "/home/$username/Downloads/";
|
||||
my $flags = "rvz";
|
||||
my $verbose;
|
||||
my $help;
|
||||
|
||||
# options
|
||||
my $result = GetOptions ( "file=s" => \$file,
|
||||
"host=s" => \$host,
|
||||
"directory=s" => \$directory,
|
||||
"user=s" => \$user,
|
||||
"dest=s" => \$dest,
|
||||
"flags=s" => \$flags,
|
||||
"verbose" => \$verbose,
|
||||
"help" => \$help);
|
||||
|
||||
### Begin main logic
|
||||
# help catch
|
||||
if ($help) {
|
||||
help();
|
||||
|
||||
}
|
||||
# If we have all the right arguments, begin the copy
|
||||
elsif (length $file && length $host && length $user && length $dest && length $directory) {
|
||||
|
||||
# Open our filehandle
|
||||
open my $info, $file or die "Could not open $file: $!";
|
||||
|
||||
# read line by line
|
||||
while( my $line = <$info> ) {
|
||||
chomp $line;
|
||||
# actual copy logic
|
||||
if (length $verbose) {
|
||||
system("rsync", "-vvv", "-$flags", "$directory/$line", "$user\@$host:$dest");
|
||||
} else {
|
||||
system("rsync", "-$flags", "$directory/$line", "$user\@$host:$dest");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
# if we fail the variables check, print usage help
|
||||
else {
|
||||
help();
|
||||
}
|
||||
|
||||
# help subroutine
|
||||
sub help {
|
||||
print "Usage: $ARGV[0] --file= --host= --directory= --user= --dest= --flags= [--verbose] [--help]\n
|
||||
--file - Input file to read with list of files/folders to transfer \n
|
||||
--host - IP address or hostname of the remote system\n
|
||||
--directory - Relative or absolute path to the folder containing the files/folders to transfer, \n
|
||||
with no trailing slash\n
|
||||
--user - User account on the remote system to use\n
|
||||
--dest - Destination on the remote system to copy files to\n
|
||||
--flags - rsync flags to use when copying the files over\n
|
||||
--verbose - run rsync with -vvv\n
|
||||
--help - show this help\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user