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

i am wondering how i can get the communication between the servers when using Net::FTP the part that looks like

PWD 257 "/" is current directory. PASV 227 Entering Passive Mode (216,113,198,37,11,170). connecting data channel to 216.113.198.37:2986 data channel connected to 216.113.198.37:2986 LIST 150 Opening ASCII mode data connection for file list Success transferred 724 bytes in 1.270 seconds, 4.454 Kbps ( 570.079 Bps). 226 Transfer complete.

i cant figure it out, and cant find any doc on how to do it. any help apreciated :)

Edit by tye (one-word titles trip up future searches)

Replies are listed 'Best First'.
(shockme) Re: FTP
by shockme (Chaplain) on Dec 28, 2001 at 10:18 UTC
    Without any code, it's difficult to know what you're trying to do. However, following is a script I wrote to automate the download of all files in a give directory, or simply a given file. It's quick and dirty, and I'm sure could be cleaned considerably, but when I wrote it, I needed it "yesterday".....

    #!/usr/bin/perl # # gets $FILE in $DIR from $HOST # # the following command line parameters are accepted: # # -h host IP and port (ex: 192.168.1.1 22) # -u userid (ex: -u anonymous) # -p password (ex: -p your@email.com) # -d directory (ex: -d /pub/data/) # -f file (ex: -f filename.txt) # NOTE: if -f is not passed, then the entire directory is downlo +aded $BadInput = ""; use Getopt::Long; GetOptions("h=s" => \$HOST, "port=s" => \$PORT, "u=s" => \$USERNAME, "p=s" => \$PASSWORD, "d=s" => \$DIR, "f=s" => \$FILE); use File::stat; $fileinfo = stat("$ENV{HOME}.batchftprc"); if (!($HOST)) { print "No host specified\n"; $BadInput = "Y"; } if (!($USERNAME)) { print "No userid specified\n"; $BadInput = "Y"; } if (!($PASSWORD)) { print "No password specified\n"; } if ((!($DIR)) and (!(-s("$ENV{HOME}/.batchftprc")))) { print "No directory specified\n"; $BadInput = "Y"; } if ($BadInput) { print "correct usage is: perl batchftp.pl --h=<HOST> [--port=< +PORT>] --u=<USERID> --p=<PASSWORD> --d=<DIRECTORY> [--f=<FILENAME>]\n +"; print "items enclosed in [] are optional\n"; print "-d is required unless $ENV{HOME}/.batchftprc exists\n"; print "probably want to use & as well\n"; exit; } if ($DIR) { push(@dir, $DIR); } else { open(CONFIG, "$ENV{HOME}/.batchftprc") or die "-d not specifie +d and could not open $ENV{HOME}/.batchftprc: $!"; while (chomp($DIR = <CONFIG>)) { push(@dir, $DIR); } } use Net::FTP; $ftp = Net::FTP->new("$HOST $PORT") or die "can't connect to $HO +ST: $!\n"; $ftp->login($USERNAME, $PASSWORD) or die "can't login: $!\n"; foreach $DIR (@dir) { $ftp->cwd($DIR) or die "can't change to $DIR +: $!\n"; if ($FILE) { $ftp->get($FILE) or die "can't get $FILE: $!\ +n"; } else { @list = $ftp->ls or die "can't get ls: $!\n"; foreach $FILE (@list) { $ftp->get($FILE) or die "in foreach can't get + $FILE: $!\n"; } } } $ftp->quit;

    The format of .batchftprc is:

    /directory01/whatever /directory02 /directory03/whatever/you/want

    Hope this helps.

    If things get any worse, I'll have to ask you to stop helping me.

Re: FTP
by robin (Chaplain) on Dec 28, 2001 at 16:40 UTC
    It sounds as though you want to see the raw FTP commands and responses. You can pass the option     Debug => 1, as an argument to Net::FTP->new(). Alternatively, you can call $ftp->debug(1); on your Net::FTP object. The raw commands and responses will be printed to STDERR. Here's an example program:
    #!/usr/bin/perl -w use strict; use Net::FTP; my $ftp = Net::FTP->new("ftp.cpan.org", Debug => 1); $ftp->login("anonymous", 'boutros@boutros-ghali.com'); $ftp->cwd("/pub/CPAN"); $ftp->get("README", '/tmp/CPAN-README'); $ftp->quit;
    and its output:
    Net::FTP: Net::FTP(2.58) Net::FTP: Exporter(5.562) Net::FTP: Net::Cmd(2.19) Net::FTP: IO::Socket::INET(1.25) Net::FTP: IO::Socket(1.26) Net::FTP: IO::Handle(1.21) Net::FTP=GLOB(0x1c1dbc)<<< 220 siobhra.indigo.ie FTP server (Version + 6.00) ready. Net::FTP=GLOB(0x1c1dbc)>>> user anonymous Net::FTP=GLOB(0x1c1dbc)<<< 331 Guest login ok, send your email addre +ss as password. Net::FTP=GLOB(0x1c1dbc)>>> PASS .... Net::FTP=GLOB(0x1c1dbc)<<< 230 Guest login ok, access restrictions a +pply. Net::FTP=GLOB(0x1c1dbc)>>> CWD /pub/CPAN Net::FTP=GLOB(0x1c1dbc)<<< 250 CWD command successful. Net::FTP=GLOB(0x1c1dbc)>>> PORT 62,136,150,113,192,10 Net::FTP=GLOB(0x1c1dbc)<<< 200 PORT command successful. Net::FTP=GLOB(0x1c1dbc)>>> RETR README Net::FTP=GLOB(0x1c1dbc)<<< 150 Opening ASCII mode data connection fo +r 'README' (1941 bytes). Net::FTP=GLOB(0x1c1dbc)<<< 226 Transfer complete. Net::FTP=GLOB(0x1c1dbc)>>> QUIT Net::FTP=GLOB(0x1c1dbc)<<< 221 Goodbye.
Re: FTP
by kjherron (Pilgrim) on Dec 28, 2001 at 10:18 UTC
    Check the documentation on the Net::Cmd module. These methods can be used on Net::FTP objects, and they give you access to all the protocol messages and such.
Re: FTP
by petral (Curate) on Dec 28, 2001 at 12:50 UTC
    If you use Net::FTP as shown above, you can
    warn $ftp->message();
    to see the responses to your commands with their 100-500 numbers and all.

      p