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

Perl 通过ftp将文件上载到特定远程目录失败,perl,ftp,Perl,Ftp,我正试图用perl脚本中的ftp将一个文件从本地Windows7客户端上传到远程linux服务器。我正在使用Net::FTP模块。我想在/home/myname/Uploads/coworkers.json目录中创建remote.json文件。脚本显示了以下错误: script.pl第148行的文件描述符不正确:无法创建文件 script.pl摘录: my ($ftp, $host, $user, $pass, $fname, $remotedir, $rfile); $host = "xx

我正试图用perl脚本中的ftp将一个文件从本地Windows7客户端上传到远程linux服务器。我正在使用Net::FTP模块。我想在/home/myname/Uploads/coworkers.json目录中创建remote.json文件。脚本显示了以下错误:

script.pl第148行的文件描述符不正确:无法创建文件

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终端中,我键入了

sudo chown myuser:myuser上载

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

/主页/我的用户/上传


没有对该目录的权限,或者已存在具有该名称的写保护文件。请将“调试”设置为1,并将输出包括在问题中。或者至少显示$ftp->消息,而不是死掉。很可能它包含了上传失败的原因。@Steffen Ullrich:我添加了调试输出,但我不知道更多的信息如何帮助解决我的问题。@MartinPrikryl:不,我不能。当ftp>put coworkers.json coworkers.json时,会显示:200端口命令成功。考虑使用PASV。553无法创建文件。那么您没有编程问题。请到。