我做了一堆阅读和一些测试无济于事。
我在 stackoverflow 上找到了这个脚本,它引导我朝着正确的方向前进,但是我的能力不足以修改和完全理解我的需求。
#! /usr/bin/perl
use warnings;
use strict;
use File::Basename;
use File::Copy;
use File::Spec::Functions qw/ abs2rel catfile /;
use Net::SSH qw/ sshopen3 /;
my $HOST = "user\@host.com";
my $SRC_BASE = "/tmp/host";
my $SRC_FILE = "$SRC_BASE/a/b/c/file";
my $DST_BASE = "/tmp/dest";
system("md5sum", $SRC_FILE) == 0 or exit 1;
my $dst_file = catfile $DST_BASE, abs2rel $SRC_FILE, $SRC_BASE;
my $dst_dir = dirname $dst_file;
sshopen3 $HOST, *SEND, *RECV, *ERRORS,
"mkdir -p $dst_dir && cat >$dst_file && md5sum $dst_file"
or die "$0: ssh: $!";
binmode SEND;
copy $SRC_FILE, \*SEND or die "$0: copy failed: $!";
close SEND or warn "$0: close: $!"; # later reads hang without this
undef $/;
my $errors = <ERRORS>;
warn $errors if $errors =~ /\S/;
close ERRORS or warn "$0: close: $!";
print <RECV>;
close RECV or warn "$0: close: $!";
设想:
我在“主”主机的目录中有图像文件,例如/home/user/public_html/images/red/id100/image01.jpg (thru image012.jpg)
如果!-d,我想将它们复制/发送到创建 red/id100 路径的远程主机。(“/images”文件夹预先存在。)
我还需要向远程主机发送用户名和密码才能进入。这是一个典型的 cpanel 共享服务器环境。
我的主服务器是专用的,也安装了 cpanel 管理。
我查看了 NET::FTP、File::Remote、Net::Telnet 和 Net::SFTP,但是没有可用的示例被“愚蠢”到我的水平。
我最终也需要对 ascii 文件执行此操作,但我相信,一旦我使用图像,我就可以弄清楚 xfermode 开关,我希望。
感谢您提供任何帮助和详细示例。我总是在这里学到很棒的东西。