Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bad File Descriptor using NET::ftp

Status
Not open for further replies.

pcutler

Technical User
Jan 18, 2002
59
0
0
CA
Hi,

I'm playing around with NET::ftp, and I've run into a problem.

I'm trying to write a script that will automatically FTP files to a remote server.

Here's what I've tried:

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
use Net::FTP;

my $host = "XXX.XX.XXX.XX";
my $username = "UNAME";
my $password = "PASSW";
my $ftpdir = "/";
my $file = "C:\\Today.txt";

#-- connect to ftp server
my $ftp = Net::FTP->new($host) or die "Error connecting to $host: $!";

#-- login
$ftp->login($username,$password) or die "Login failed: $!";

#-- set to binary
$ftp->binary();

#-- chdir to $ftpdir
$ftp->cwd($ftpdir) or die "Can't go to $ftpdir: $!";

#-- upload file
$ftp->put($file) or die "Can't get $file: $!";

#-- close ftp connection
$ftp->quit or die "Error closing ftp connection: $!";

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&


When I run the script, I get this error:

"Can't get C:\Today.txt: Bad file descriptor at ftp_test.pl line 26." (that's the line after "#-- upload file"

What am I doing wrong?

When it's up and running, I want the script to look in a folder on the local machine, and upload all the files (40-60 per day) with a .pdf extension to the server. How would I use mput with NET::ftp to do this?

Thanks for your time.


Peter.

 
Try this:
my $file = "C:\\Today.txt";
my $file = 'C:\\Today.txt';

You can scheudule a task, if on windows, to run a script, that would pick up the files with .pdf extension in the dir and ftp them over.
 
max1x:

Code:
my $file1 = "C:\\Today.txt";
my $file2 = 'C:\\Today.txt';
print $file1,"\n",$file2;

prints:

C:\Today.txt
C:\Today.txt



------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Max1x,

I had already tried that.

The does variable print the correct file name, but NET::ftp still fails with a "Bad file descriptor" error.

I can complete the transfer by hand without trouble.

What am I missing?

Peter.
 
I don't have windows machine, so I can't test..., can u try escaping the 2nd \ with a \ and see if that get's the job done (\\\\)? I thought I had read on this forum that windows dir stucture is treated like *nix with active perl, but I can't be for sure...u can try that as well...
 
As it turns out, the issue had nothing to do with PERL after all.

I was running the script from within a VM.

Once I moved it off the VM to a regular system, It worked fine.

Peter.
 
I don't have windows machine, so I can't test..., can u try escaping the 2nd \ with a \ and see if that get's the job done (\\\\)? I thought I had read on this forum that windows dir stucture is treated like *nix with active perl, but I can't be for sure...u can try that as well...

Not true. Windows, since its inception, has supported forward slashes in directory paths and continues to support them. If you use backslashes in your windows directory path definitions with activeperl the best thing to do is use single-quotes:

$path = 'C:\Windows';

perl will interpolate that correctly and Windows will open the directory or file. But it is safer to use forwad slashes even with activeperl:

$path = 'C:/Windows';

The only time you need to escape inside a single-quoted string is a backslash at the end:

$path = 'C:\Windows\'; <-- bad
$path = 'C:\Windows\\'; <-- OK
$path = 'C:\Windows; <-- good
$path = 'C:/Windows/'; <-- OK
$path = 'C:/Windows'; <-- good

You also need to escape embedded single-quotes or use the q{} operator which does the escapes for you.


------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Should have been:

$path = 'C:\Windows\'; <-- bad
$path = 'C:\Windows\\'; <-- OK
$path = 'C:\Windows'; <-- good
$path = 'C:/Windows/'; <-- OK
$path = 'C:/Windows'; <-- good


------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top