Reputation: 629
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. I am using the Net::FTP module. I want to create the remote .json file in the directory /home/myname/Uploads/coworkers.json . The script gives me this error:
Bad file descriptor at script.pl line 148: CANNOT CREATE FILE.
script.pl (excerpt):
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:
...
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.
Upvotes: 0
Views: 808
Reputation: 629
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. In the Linux terminal on my remote server I typed...
sudo chown myuser:myuser Uploads
After running the script again, the file was successfully created on the remote server inside the directory
/home/myuser/Uploads
Upvotes: 1