简体   繁体   English

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

[英]Uploading file via ftp to specific remote directory fails

I am trying to upload one single file from my local windows 7 client to my remote linux server with ftp inside my perl script.我正在尝试使用我的 perl 脚本中的 ftp 将一个文件从我的本地 Windows 7 客户端上传到我的远程 linux 服务器。 I am using the Net::FTP module.我正在使用 Net::FTP 模块。 I want to create the remote .json file in the directory /home/myname/Uploads/coworkers.json .我想在目录 /home/myname/Uploads/coworkers.json 中创建远程 .json 文件。 The script gives me this error:脚本给了我这个错误:

Bad file descriptor at script.pl line 148: CANNOT CREATE FILE . script.pl 第 148 行的文件描述符错误:无法创建文件

script.pl (excerpt): 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;

When Debugging is set to 1, this is the output:当调试设置为 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.

My folder Uploads on the remote server was created by the root user, which is why I didn't have permissions to create files inside of it.我在远程服务器上的文件夹 Uploads 是由 root 用户创建的,这就是我无权在其中创建文件的原因。 In the Linux terminal on my remote server I typed...在远程服务器上的 Linux 终端中,我输入了...

sudo chown myuser:myuser Uploads sudo chown myuser:myuser 上传

After running the script again, the file was successfully created on the remote server inside the directory再次运行脚本后,在远程服务器上的目录里面成功创建了文件

/home/myuser/Uploads /home/myuser/上传

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM