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

I am now responsible for the Voice over IP project in our company, and one of the things that I will be doing is updating the outbound phonebooks for the VoIP equipment at all 58 of our remote sites. The equipment in question automatically reboots itself upon receipt of the new phonebook, so the ftp connection will not be closing out cleanly. Also, it is sending some information back when I use a manual client (WS_FTP) to connect to it. An example from the log is shown below:
connecting to 128.1.198.22...
Connected to 128.1.198.22 port 21
220 Service ready
USER mvpadmin
331 User name ok, need password
PASS (hidden)
230 User logged in
PWD
257 "/"
Host type (I): UNIX (standard)
PORT 128,1,208,162,19,38
200 Command OK
LIST
150 Here it comes...
Received 52 bytes in 1.0 secs, (51.90 Bps), transfer succeeded
226 Transfer Ok, Closing connection
Now I know that the last two lines are what is being displayed to my FTP program from the remote directory on the VoIP equipment. How would I deal with the line "150 Here it comes..."? my current test script receives the following error: "getsockname() on closed socket GEN0 at D:/Perl/lib/IO/Socket.pm line 192"
As always, here is the test code:
#!perl -w use strict; use Net::FTP; my $user="mvpadmin"; my $pass="mypassword"; my $opb="D:\\MVP\\OutPhBk.tmr"; my $mvp="128.1.198.22"; my $FTP=Net::FTP->new($mvp,Timeout=>20); my $login=$FTP->login($user,$pass); if(!defined $login){ die"Unable to connect: $!\n"; }else{ print"Connected to $mvp\n"; } $FTP->binary; $FTP->put($opb); $FTP->close;

TStanley
--------

Replies are listed 'Best First'.
Re: FTP automation
by derby (Abbot) on Jun 27, 2003 at 18:00 UTC
    Hmm ... I don't quite understand what the problem is since your manual ftp session is different than your scripted session. In the manual, you just list the contents of the remote machine. The numbered lines are the control channel and the Net::FTP module hides that from you (you shouldn't need to worry about it). See RFC959 for more info on the inner workings of ftp (control -vs- data channels).

    In your scripted ftp session you state you're getting a "closed socket" error which is what I would expect given initial statement The equipment in question automatically reboots itself upon receipt of the new phonebook. So how would I handle the error? I wouldn't. I would just check the return value of the put and if okay, just exit:

    $FTP->put( $opb ) || die "An error occurred with put"; print "All is well ... exiting\n";

    -derby

      When FTP'ing... I always PUT the file as a temporary name, then at least do a DIR to check that the entire file got there (byte count the same using bin mode transfer, no clue what you'd do if not and didn't want to GET the file back) then I rename the file to the desired name, thus preventing anything looking for the file from acting on a partial file. should also help out here.
      Unfortunately, the equipment is not rebooting itself when it gets the phonebook (It is setting on a shelf at eye level, and the boot light doesn't come on). I can attempt to send an ls command to it, but I get the same error message as above.

      TStanley
      --------
        stange indeed. Have you tried setting the debug flag to see if anything odd pops up (need for passive mode? timeout? etc?)

        my $FTP=Net::FTP->new($mvp, Timeout=>20, Debug => 1);

        -derby