通过 ftp 将文件上载到特定远程目录失败



我正在尝试将一个文件从我的本地Windows 7客户端上传到我的远程Linux服务器,在我的perl脚本中使用ftp。我正在使用网络::FTP模块。我想在目录/home/myname/Uploads/coworkers.json 中创建远程 .json 文件。脚本给了我这个错误:

第 148 行 script.pl 文件描述符错误:无法创建文件

script.pl(摘录(:

my ($ftp, $host, $user, $pass, $fname, $remotedir, $rfile);
$host = "xxx.xxx.xxx.xxx";
$user = "myname";
$pass = "mypw";
$remotedir = "/home/myname/Uploads/";
$fname = "coworkers.json";
$ftp = Net::FTP->new($host, Debug => 0) or die "Connection to $host failed: $@";
print $ftp->message;
$ftp->login($user, $pass) || die $ftp->message;
print $ftp->message; # LOGIN SUCCESSFUL
$ftp->cwd($remotedir);
print $ftp->message; # DIRECTORY SUCCESSFULLY CHANGED
$ftp->put($fname, $fname) or die "$!"; # ERROR line 148
print $ftp->message;
$ftp->quit;
print $ftp->message;

当"调试"设置为 1 时,输出如下:

...
Login successful.
Net::FTP=GLOB(0x....)>>>> CWD /home/myuser/Uploads/
Net::FTP=GLOB(0x....)><<< 250 Directory successfully changed.
Directory successfully changed.
Net::FTP=GLOB(0x....)>>>> PASV
Net::FTP=GLOB(0x....)><<< 227 Entering Passive Mode (xx,xx,xx,xx,218,232).
Net::FTP=GLOB(0x....)>>>> STOR coworkers.json
Net::FTP=GLOB(0x....)><<< 553 Could not create file.
Bad file descriptor at script.pl line 148.

我的文件夹 远程服务器上的上传是由 root 用户创建的,这就是为什么我没有权限在其中创建文件的原因。在我的远程服务器上的 Linux 终端中,我键入了...

须藤羚羊 我的用户:我的用户上传

再次运行脚本后,在目录内的远程服务器上成功创建了文件

/

首页/我的用户/上传

最新更新