Automatically upload the entire directory with Perl

xiaoxiao2021-03-06  117

Three years ago (copy) Writing, I use it today, so I found it. Stay here.

#! / usr / bin / perl -w

Use net :: ftp; use strict;

My $ server = 'xxx.xxx.xxx.xxx'; my $ user = 'foo'; my $ PW = 'bar'; my $ rdir = '/ to';

MY $ ftp = net :: ftp-> new ($ server); $ ftp-> login ($ user, $ pw) || DIE "login failed";

$ ftp-> mkdir ($ RDIR, 1);

$ FTP-> CWD ($ RDIR) || Die Print "$ RDIR DOESN '' SEEM to EXIST On $ Server. / N";

MY $ remote_start_dir = $ ftp-> pwd ();

MY $ local_start_dir = '/ from'; # my $ local_start_dir = $ env {pwd};

Handle_Dir ($ local_start_dir, $ transote_start_dir);

Sub Handle_Dir () {MY $ local = $ _ [0]; My $ remote = $ _ [1]; OpenDir (Dir, $ local) || DIE "huh? $!"; $ ftp-> mkdir ($ remote 1) || DIE "Can't Make $ Remote On $ Server / N"; my @subdirs; my @all_files = grep! ///./.? $ /, Readdir Dir; foreach (@all_files) {IF (-d $ local. "/". $ _) {push @Subdirs, $ _;} else {$ ftp-> put ($ local. "/". $ _, $ transote. "/". $ _) || DIE "$!";}}

Foreach (@subdirs) {handle_dir ($ local. "/". $ _, $ transote. "/". $ _);}}

$ ftp-> quit;

转载请注明原文地址:https://www.9cbs.com/read-125824.html

New Post(0)