8 # The protocol consists of repeated exchanges of the following:
11 # S: <each line of file, with dot-stuffing as in SMTP>
21 my $sshmovepath = 'ssh-move';
26 local $_ = shift @ARGV;
29 } elsif (/^--verbose$/) {
31 } elsif (/^--ssh-identity$/) {
32 $sshidentity = shift @ARGV;
33 } elsif (/^--ssh-move-path$/) {
34 $sshmovepath = shift @ARGV;
35 } elsif (/^--from-directory$/) {
36 $fromdir = shift @ARGV;
37 } elsif (/^--to-directory$/) {
39 } elsif (/^--non-interactive$/) {
50 my ($in, $out) = (*STDIN, *STDOUT);
53 my $servername = shift @ARGV;
54 local (*READER, *WRITER);
57 push @args, '-i', $sshidentity if defined $sshidentity;
59 push @args, $servername, $sshmovepath;
60 push @args, '--server' unless ($server);
61 push @args, '--to-directory', $todir if (defined $todir && $server);
62 push @args, '--from-directory', $fromdir if (defined $fromdir && !$server);
63 push @args, '--non-interactive';
64 push @args, map quotemeta, @ARGV unless ($server);
66 my $pid = open2 (\*READER, \*WRITER, @args);
68 ($in, $out) = (*READER, *WRITER);
73 chdir $fromdir if defined $fromdir;
75 my @files = map glob, @ARGV;
77 for my $file (@files) {
78 print $out "$file\n" or die "can't print to client: $!";
79 open FILE, "< $file" or die "can't open $file: $!\n";
84 print $out "$_\n" or die "can't print to client: $!";
86 print $out ".\n" or die "can't print to client: $!";
89 chomp $confirm if defined $confirm;
90 unlink $file if defined $confirm and $confirm eq $file;
96 chdir $todir if defined $todir;
99 while (defined ($file = <$in>)) {
101 print STDERR $file if $verbose;
102 (my $tmpfile = $file) =~ s[.*/][];
103 $tmpfile .= ".$$.tmp";
104 # TODO: unlink $tmpfile if things go wrong
105 open TMP, "> $tmpfile" or die "can't open $tmpfile: $!";
110 close TMP or die "can't close $tmpfile: $!";
111 rename $tmpfile, $file
112 or die "can't rename $tmpfile to $file: $!";
113 print $out "$file\n" or die "can't print to server: $!";
117 print TMP "$_\n" or die "can't print to $tmpfile: $!";
120 print STDERR " ok\n" if $verbose;