FTP from Perl script on Windows

I

Ivan L

I have tried to use FTP from Perl (not using System() but directly from perl script), and
found out that all the sample programs found on the Internet don't work. Further investigation showed
that there is following error

"Cannot connect to host: Net::FTP: Bad protocol 'tcp' at ftptest1.pl line 3."

The part of the perl script that caused this error is:

1.#!/usr/bin/perl -w
2. use Net::FTP;
3. $ftp = Net::FTP->new("Host", Debug => 0) or die "Cannot connect to host: $@";

I use Windows XP SP2 and ActiveState Perl 5.8.7. Also, I have tried to use Windows 2003
server, with the same result.
Can anybody help with this? The FTP server on machine "host" is up and running, using command
line I can FTP without problem.
 
S

Sisyphus

Ivan L said:
I have tried to use FTP from Perl (not using System() but directly from perl script), and
found out that all the sample programs found on the Internet don't work. Further investigation showed
that there is following error

"Cannot connect to host: Net::FTP: Bad protocol 'tcp' at ftptest1.pl line 3."

The part of the perl script that caused this error is:

1.#!/usr/bin/perl -w
2. use Net::FTP;
3. $ftp = Net::FTP->new("Host", Debug => 0) or die "Cannot connect to host: $@";

Can't see anything that should pose a problem (assuming "Host" is replaced
by the valid string for whatever your host really is).

The following works fine for me on Win32:

use warnings;
use Net::FTP;
$ftp = Net::FTP->new("rtfm.mit.edu", Debug => 1)
or die "Cannot connect to host: $@";
$ftp->login('anonymous','anonymous');
$ftp->cwd("/pub/usenet-by-group/");
$ftp->quit;

What does that script produce for you ?

Cheers,
Rob
 
I

Ivan L

Hi Sisyphus,
Unfortunately the result is the same - the message is :
Cannot connect to host: Net::FTP: Bad protocol 'tcp' at C:\PROGRA~1\PERLEX~1\Scripts
\FTPPER~1.PL line 4.
I copied your script and put my host name...

I have all firewalls down and tried to connect to my localhost FTP server to exclude
networking troubles, but it didn't change anything...
 
D

Dr.Ruud

Ivan L schreef:
"Cannot connect to host: Net::FTP: Bad protocol 'tcp' at ftptest1.pl
line 3."

Check out the file "%windir%\system32\drivers\etc\protocol".
 
B

Ben Morrow

Quoth l v said:
s/protocol/services/

Err.. really not. /etc/protocol ne /etc/services; if you don't
understand the difference between them please don't try to correct those
who do.

Ben
 
D

Dr.Ruud

l v schreef:
Ivan L:
[attribution corrupted]
[attribution corrupted]
"Cannot connect to host: Net::FTP: Bad protocol 'tcp' at
ftptest1.pl line 3."

Check out the file "%windir%\system32\drivers\etc\protocol".

There is no "%windir%\system32\drivers\etc\protocol" file on my
machine.

s/protocol/services/

The error message was "Bad protocol 'tcp'".
The "services" file contains a list of names for selected port/protocol
combinations.

Ivan, did you understand "%windir%"? It's an environment variable that
has the value "C:\WINNT" on some systems, "C:\Windows" on other systems,
and other values on yet other systems. Go to a command prompt and enter
"set" to get the value on your system.
 
S

Sisyphus

Ivan L said:
Hi Sisyphus,
Unfortunately the result is the same - the message is :
Cannot connect to host: Net::FTP: Bad protocol 'tcp' at C:\PROGRA~1\PERLEX~1\Scripts
\FTPPER~1.PL line 4.
I copied your script and put my host name...

It was my intention that you use that script as is. (You should be able to
connect to that ftp server.)

However, I get the feeling that the other respondents might be pushing you
in a more pertinent direction.

Cheers,
Rob
 
I

Ivan L

I know about %windir% environment variable. However, there is no protocol file (or
folder) in the c:\Windows\System32\drivers\etc\ There are, however, several files
named services (services, services01, services02 ...) that happen to be empty.



Dr.Ruud said:
l v schreef:
Ivan L:
[attribution corrupted]
[attribution corrupted]
"Cannot connect to host: Net::FTP: Bad protocol 'tcp' at
ftptest1.pl line 3."

Check out the file "%windir%\system32\drivers\etc\protocol".

There is no "%windir%\system32\drivers\etc\protocol" file on my
machine.

s/protocol/services/

The error message was "Bad protocol 'tcp'".
The "services" file contains a list of names for selected port/protocol
combinations.

Ivan, did you understand "%windir%"? It's an environment variable that
has the value "C:\WINNT" on some systems, "C:\Windows" on other systems,
and other values on yet other systems. Go to a command prompt and enter
"set" to get the value on your system.
 
I

Ivan Lackic

I have tried to run your FTP script on some other machine and it worked well. I guess
that it is a matter of some XP setting or some security programs running on the first
machine...
regards,
I.
 
B

Ben Morrow

[please don't top-post]

Quoth Ivan L said:
I know about %windir% environment variable. However, there is no
protocol file (or
folder) in the c:\Windows\System32\drivers\etc\ There are, however,
several files
named services (services, services01, services02 ...) that happen to be empty.

That directory should have (or at least, my Win2k installation has)
files called hosts, lmhosts.sam, networks, protocol, and services. They
should have at least the following entries:

hosts
127.0.0.1 localhost

networks
loopback 127

protocol
ip 0 IP
icmp 1 ICMP
tcp 6 TCP
udp 17 UDP

services
# a whole list of standard services

If they don't, the networking part of your windows install is severely
broken, and you need to fix it before you can use sockets with Perl.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top