FTP上传目录和Perl中的子目录

时间:2015-07-03 09:08:48

标签: perl ftp

我正在尝试使用Perl来FTP一个包含带有文件和图像的子目录的目录。

我尝试在$ftp->rput()下使用Net::FTP::Recursive。但是这会上传本地当前工作目录下的所有文件。

是否有办法提供本地目录的路径,并上传所有文件夹和文件。请指导。

1 个答案:

答案 0 :(得分:3)

您需要暂时更改自己的工作目录。

rput ( [FlattenTree => 1] [,RemoveLocalFiles => 1] )
     

递归放置   方法调用。这将以递归方式发送本地当前工作   目录及其内容到ftp对象的当前工作   。目录

Perl的builtin chdir可用于更改目录。如果您需要返回,请使用Cwd module获取当前的。{/ p>

use strict; 
use warnings;
use Cwd;
use Net::FTP::Recursive;

# ...

# get the current directory
my $old_current_dir = getcwd();

# change directory to the one you want to upload
chdir('path/to/updloaddir');

# upload
$ftp->rput();

# change back
chdir($old_current_dir);
相关问题