FTP from Perl script on Windows

Discussion in 'Perl Misc' started by Ivan L, Sep 28, 2006.

  1. Ivan L

    Ivan L Guest

    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.
     
    Ivan L, Sep 28, 2006
    #1
    1. Advertising

  2. Ivan L

    Sisyphus Guest

    "Ivan L" <> wrote in message
    news:Xns984C6A9E0F938ivanlac@213.191.133.136...
    >
    > 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
     
    Sisyphus, Sep 28, 2006
    #2
    1. Advertising

  3. Ivan L

    Ivan L Guest

    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...


    "Sisyphus" <> wrote in news:451b90ea$0$11972$afc38c87
    @news.optusnet.com.au:

    > 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;
    >
     
    Ivan L, Sep 28, 2006
    #3
  4. Ivan L

    Dr.Ruud Guest

    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".

    --
    Affijn, Ruud

    "Gewoon is een tijger."
     
    Dr.Ruud, Sep 28, 2006
    #4
  5. Ivan L

    Ivan L Guest

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

    "Dr.Ruud" <> wrote in news::

    > 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".
    >
     
    Ivan L, Sep 28, 2006
    #5
  6. Ivan L

    Ben Morrow Guest

    Quoth l v <>:
    > Ivan L wrote:
    > > There is no "%windir%\system32\drivers\etc\protocol" file on my machine.
    > >
    > > "Dr.Ruud" <> wrote in

    > news::
    > >
    > >> 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".

    >
    > 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

    --
    'Deserve [death]? I daresay he did. Many live that deserve death. And some die
    that deserve life. Can you give it to them? Then do not be too eager to deal
    out death in judgement. For even the very wise cannot see all ends.'
     
    Ben Morrow, Sep 28, 2006
    #6
  7. Ivan L

    Dr.Ruud Guest

    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.

    --
    Affijn, Ruud

    "Gewoon is een tijger."
     
    Dr.Ruud, Sep 29, 2006
    #7
  8. Ivan L

    Sisyphus Guest

    "Ivan L" <> wrote in message
    news:Xns984C73F311E2Bivanlac@213.191.133.136...
    > 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
     
    Sisyphus, Sep 29, 2006
    #8
  9. Ivan L

    Ivan L Guest

    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" <> wrote in news::

    > 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.
    >
     
    Ivan L, Sep 29, 2006
    #9
  10. Ivan L

    Ivan Lackic Guest

    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.


    "Sisyphus" <> wrote in
    news:451cc139$0$11971$:

    >
    > "Ivan L" <> wrote in message
    > news:Xns984C73F311E2Bivanlac@213.191.133.136...



    >> 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
    >
    >
     
    Ivan Lackic, Sep 29, 2006
    #10
  11. Ivan L

    Ben Morrow Guest

    [please don't top-post]

    Quoth 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.


    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

    --
    You poor take courage, you rich take care:
    The Earth was made a common treasury for everyone to share
    All things in common, all people one. []
    'We come in peace'---the order came to cut them down.
     
    Ben Morrow, Sep 29, 2006
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dpackwood
    Replies:
    3
    Views:
    1,872
  2. someone

    FTP over SSL vs FTP over SSH

    someone, Apr 24, 2004, in forum: Java
    Replies:
    1
    Views:
    4,651
    iksrazal
    Apr 25, 2004
  3. Replies:
    3
    Views:
    5,783
  4. D. Buck
    Replies:
    2
    Views:
    601
    D. Buck
    Jun 29, 2004
  5. Replies:
    3
    Views:
    227
    John Mason Jr
    Dec 18, 2004
Loading...

Share This Page