If you don't want to use perl modules you probably need to script SCP(1). Here is an edited bit of code from a backup script that should get you started
my $SCP = '/usr/bin/scp';
my $KEYFILE = '/root/.ssh/id_rsa';
my $CVS = "$BACKUP/CVS-$REMOTE_HOST";
my $REMOTE_PATH = "$REMOTE_USER\@$REMOTE_HOST:$REMOTE_PATH";
my $res = `$SCP -o Protocol=2 -i $KEYFILE -c blowfish -B -p $REMOTE_PA
+TH $CVS 2>&1`;
$res =~ s/[^\n\040-\177]//g;
warn $res ? "scp failed and returned:\n$res\n\n" : "scp succeeded!\n\n
+";
| [reply] [Watch: Dir/Any] [d/l] |
You could just use scp. scp is way better than sftp for scripting, IMO. And also, for sysadmin type tasks, I would rather use Perl as glue, than try to reinvent tools with it just to do it in Pure Perl. Just too... religious, for me.
I use public/private keys for authentication in this case, because not only is it (only slighter) safer than putting the password in the script, but it removes the need to interact with scp in order to transfer files.
perl -e '@hosts = ( map { $_ . q[.example.com] } qw/ foo bar www / );
+system( q[scp], q[-r], @ARGV, sprintf(q[%s:remotedir], $_) ) foreach
+@hosts;' /tmp/foo
Here is another version using ssh and rsync, so as to only send the parts that changed, and ignores .CVS files:
perl -e '@hosts = ( map { $_ . q[.example.com] } qw/ foo bar www / );
+system( q[rsync], q[-rcC], q[-e], q[ssh], @ARGV, sprintf(q[%s:remoted
+ir], $_) ) foreach @hosts;' /tmp/foo
Of course, if the usernames on the aren't the same, you have to add that also.
| [reply] [Watch: Dir/Any] [d/l] [select] |
Depending on the particulars of what you are trying to do, you might want to look at rsync over ssh.
Just a tongue-tied, twisted, earth-bound misfit. -- Pink Floyd
| [reply] [Watch: Dir/Any] |
And for yet another way: If you have Net::SSH::Perl installed, you can also use a remote command like cat
(on a *nix system) to move files back and forth, since
Net::SSH::Perl's
cmd method lets you both capture standard output from
the remote command and supply a buffer to use
as standard input fed to the remote command.
# $data contains data from a local file to put in the
# remote file named by $to
($output, $error, $status) = $ssh->cmd("cat > $to", $data);
# On return, $output contains data from the remote file
# identified by $from (check status, etc. of course!)
($output, $error, $status) = $ssh->cmd("cat $from");
| [reply] [Watch: Dir/Any] [d/l] |
I'm curious what issues you had getting Net::SFTP installled. I've installed it on both 5.6.1 and 5.8.0 (both Solaris). Do you have specifics about the problems there? It may be easier
to fix the install than to do it another way.
| [reply] [Watch: Dir/Any] |
No I do not, and think that they will probably not give the details out. I figure these people can run circles around my meager skills and they tried getting it to run.
| [reply] [Watch: Dir/Any] |
How the heck did you get it to install on Solaris??!?!!??? I tried for two days and couldn't get the various dependencies to play nice ... I installed without a problem on various Redhats, but Solaris just wouldn't go ...
Being right, does not endow the right to be rude; politeness costs nothing. Being unknowing, is not the same as being stupid. Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence. Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.
| [reply] [Watch: Dir/Any] |