http://qs321.pair.com?node_id=394561

knovicki has asked for the wisdom of the Perl Monks concerning the following question:

I知 an Oracle DBA and rather new to Perl. I知 trying to get a custom ETL process running on a new Solaris machine, running Solaris 9, and I知 having great difficulty getting the Net::FTP process to work. The ETL process is already running on other AIX, Solaris and Windows machines, but not on this one. I have read many articles on the Internet, but I still can not resolve the problem. Below is an example of the code that I知 trying to run as well as the error:

#!/usr/bin/perl -w # test.pl use warnings; use Net::FTP; $ftp = Net::FTP->new("svr123", Debug => 1); print STDOUT ( defined $ftp ? "yep" : '$ftp' ), "\n"; $ftp->login("oracle",'xxx'); $ftp->cwd("/u01"); $ftp->put("test.dat"); $ftp->quit;
Can't call method "login" on an undefined value

The Sys Admin installed Perl as well as FTP.pm. For some reason, connection is just not being made to svr123. Using the same login information, I can use FTP interactively and it works. I知 sure it has to do with some type of installation or configuration problem, but I知 not sure what else to check. Any help would be appreciated. Thanks in advance.
Ken

20040928 Janitored by Corion: Put code in code tags

Replies are listed 'Best First'.
Re: Net::FTP.pm Blues
by dave_the_m (Monsignor) on Sep 28, 2004 at 13:26 UTC
    From the synopsis of the Net::FTP man page:
    $ftp = Net::FTP->new("some.host.name", Debug => 0) or die "Cannot connect to some.host.name: $@";

    Printing $@ on failure to create a handle should give you a good clue as to what the problem is.

    PS -I don't understand the purpose of of your print STDOUT line: if $ftp is not defined, you print its value!

    Dave.

      I'm more partial to using 'warn' instead of 'die'. That way, I can simply check to see if $ftp is undefined and handle it myself:

      just a little Oracle teasing .... ("Jason, you boob, you typed in Oracle instead of Sybase! You don't want to connect to an inferior DBMS do you?"

      Jason L. Froebe

      No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

Re: Net::FTP.pm Blues
by cfreak (Chaplain) on Sep 28, 2004 at 13:36 UTC

    I think the problem is your 'defined' call. The return value from new() may be defined even if its false. Also it appears you are trying to print out the value in the $ftp but you put it in single quotes. Perl only interpolates on double quotes.

    Anyway try calling Net::FTP like this:

    my $ftp = Net::FTP->new("srv123",Debug=>1) or die "Couldn't make an FTP connection to srv123: $@";

    If it can't make a connection that should give you the reason why

    Also a couple of other small observations that may or may not be related to your problem. The -w and use warnings; do the same thing so you really only need one of them. You should also use strict; I know that this is a small program, but it is good practice and it can help you locate hidden bugs.

    Hope that helps

Re: Net::FTP.pm Blues
by knovicki (Initiate) on Sep 28, 2004 at 14:29 UTC
    Dave,
    Thank you very much for the information. $@ provided a bit more insight into the problem. Now I at least have another error to investigate. The STDOUT line came from an example I found on the net. I tried many different variations of code to get more information. My current error is...
    Net::FTP Bad protocol 'tcp'
    It seems that
    perl -le 'print getprotobyname("tcp")'
    is not returning a value. I am currently investigating it. Once again, thanks for getting me one step further.
    Ken
      You may want to check that your /etc/protocols and /etc/nsswitch.conf files are okay:
      $ grep protocols /etc/nsswitch.conf protocols: files $ grep tcp /etc/protocols tcp 6 TCP # transmission control protocol

      Dave.

Re: Net::FTP.pm Blues
by Rhose (Priest) on Sep 28, 2004 at 13:27 UTC
    Hello knovicki, I am also an Oracle DBA who uses perl to simplify things. While I don't know for sure what the issue is, what is the output from the following code? (I'm just looking to make sure the Net::FTP install is ok.)

    #!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Net::FTP; my $ftp=Net::FTP->new('svr123', Debug => 0); print Dumper($ftp);

    Update I did run your code on one of my servers, and it worked just fine (well, I used a different server and password. *Grins*)

    Are you seeing svr123's banner output in the debug lines? For example, I get:

    Net::FTP: Net::FTP(2.56) Net::FTP: Exporter(5.562) Net::FTP: Net::Cmd(2.18) Net::FTP: IO::Socket::INET(1.25) Net::FTP: IO::Socket(1.26) Net::FTP: IO::Handle(1.21) Net::FTP=GLOB(0x182575c)<<< 220- Net::FTP=GLOB(0x182575c)<<< 220-Server: <svr123> -Server Net::FTP=GLOB(0x182575c)<<< 220-Time: Tue Sep 28 09:36:32 2004 Net::FTP=GLOB(0x182575c)<<< 220- Net::FTP=GLOB(0x182575c)<<< 220-"This system is for authorized busines +s use only. Under the Net::FTP=GLOB(0x182575c)<<< 220-Computer Fraud and Abuse Act of 1986, +it is a federal crime to Net::FTP=GLOB(0x182575c)<<< 220-obtain information from or cause damag +e to a computer used in Net::FTP=GLOB(0x182575c)<<< 220-interstate commerce when that computer + is accessed without Net::FTP=GLOB(0x182575c)<<< 220-authorization or in excess of authoriz +ed access. Unauthorized Net::FTP=GLOB(0x182575c)<<< 220-use of this equipment or system is str +ictly prohibited. Net::FTP=GLOB(0x182575c)<<< 220- Net::FTP=GLOB(0x182575c)<<< 220 <svr123> FTP server (Revision 1.002 Ve +rsion wuftpd-2.6.1 Wed Jan 2 06:26:08 GMT 2002) ready. Net::FTP=GLOB(0x182575c)>>> user oracle Net::FTP=GLOB(0x182575c)<<< 331 Password required for oracle. Net::FTP=GLOB(0x182575c)>>> PASS .... Net::FTP=GLOB(0x182575c)<<< 230 User oracle logged in. Net::FTP=GLOB(0x182575c)>>> CWD /tmp Net::FTP=GLOB(0x182575c)<<< 250 CWD command successful. Net::FTP=GLOB(0x182575c)>>> PORT <removed> Net::FTP=GLOB(0x182575c)<<< 200 PORT command successful. Net::FTP=GLOB(0x182575c)>>> STOR t.pl Net::FTP=GLOB(0x182575c)<<< 150 Opening ASCII mode data connection for + t.pl. Net::FTP=GLOB(0x182575c)<<< 226 Transfer complete. Net::FTP=GLOB(0x182575c)>>> QUIT Net::FTP=GLOB(0x182575c)<<< 221-You have transferred 242 bytes in 1 fi +les. Net::FTP=GLOB(0x182575c)<<< 221-Total traffic for this session was 115 +9 bytes in 1 transfers. Net::FTP=GLOB(0x182575c)<<< 221-Thank you for using the FTP service on + <svr123>. Net::FTP=GLOB(0x182575c)<<< 221 Goodbye.
      Hi Rhose,
      I ran your script and got the following output:
      $VAR1 = undef;
      I am starting to think it is a problem with either the Perl or FTP.pm installation. I am going to have the Unix Admin reinstall the software again. Thanks for your input.
      Ken Hi Everyone, I just wanted to tell you that my problem was finally resolved. Here is the reply from my Sys Admin "We found the issue, with the ftp perl protocal issue, there was an entry in /etc/nsswitch.conf in that we change the nsswitch.conf to use file entry first." Hope that makes sense. I wanted to provide closure to this just incase someone else ran into the same problem. Once again, thanks for all of your help. Ken
Re: Net::FTP.pm Blues
by fjaenale (Acolyte) on Sep 28, 2004 at 13:59 UTC
    Hello

    I have write thte following code and it does connect via FTP on a digital machine:

    #!/usr/bin/perl -w use Net::FTP; $ftp = Net::FTP->new("*****", Debug => 1); $ftp->login("vpn01",'******'); exit 0;

    The ***** represent hide data for the porpouse of the example. I nn my case did coneect and worked correctly. I took out the warnings package (I dont have it installed). Also I will recommend you to use "strict" and always defined variables with the instruction "my" before using them.

    Francisco Jaen
    www.cgi.com