Using NET::FTP with authenticating proxy 
Author Message
 Using NET::FTP with authenticating proxy

I am having a bear of a time with an ftp through a proxy server
requiring authentication.What we have is a situation where the script is
running on an NT machine running ActiveState Perl that is doing a ftp
connection to the firewall with a userid & password once that happens it

then need to enter the password for the follow on server. I have tried a
few variations on this and have not had any luck. Each test says that
all went well but does not return the directory listing. When I run the
script from outside the firewall and reconfigure it to not use the
firewall all runs fine and I get my directory listing.

The ultimate goal is to replace a simple batch file that has no logging
or error correction with the perl script which will do both. The basic
commands that the batch file is running are as follows:
    open ftpgate.somewhere.com
    abcuser
    userpassword

    userxyzpassword
    < balance of commands ommited to shorten >

If there is any way I can get you to take a quick look at the scripts
below and see if anything pops out at you that would be great. What I
have tried so far is as follows:

#### First Attempt ##################################################
# Firewall access information
$firewallname="ftpgate.somewhere.com";
$firewalluser="abcuser";
$firewallpassword="userpassword";

# FTP Server address, login and password
$ftpname="ftp2.SomeOtherPlace.com";

$loginname="userxyz";
$password='userxyzpassword';

# Remote directory you wish to download from (SOURCE)
$remotedirname="/motftp";
# Connect to firewall
print "Connecting to $firewallname...";
$ftp=Net::FTP->new ($firewallname, Debug => 1) or errormessage("Can\'t
connect to Firewall $firewallname - $!\n");
print "OK\n";

# Login to firewall
print "Login to firewall as $loginname...";
$ftp->login($firewalluser,$firewallpassword) or errormessage("Can\'t
login as $firewalluser/$firewallpassword- $!\n");
print "OK\n";

# Login to ftp site
#print "Follow on Login as $ftpusersite...";
$ftp->user($ftpusersite) or errormessage("Can\'t do second login as
$ftpusersite - $!\n");
$ftp->pass($password) or errormessage("Can\'t do second login password
as $password - $!\n");
print "OK\n";

#### Get directory listing for specific directory on follow on machine
####
&messageprint ("Get directory listing of $remotedirname...");

of $remotedirname - $!\n");
&messageprint ("OK\n");

{
  if (substr ($_,0,1) eq "-")                       # download files
  {
    $filesize=substr($_,30)=~/(\d+\.?\d*|\.\d+)/;   # get file size
    $filesize=sprintf "%d",$1;                      # get file size
    $filename=&getfilename($');                     # get file name
(trunc after date)
 print "$filename ($filesize)\n";

  }

Quote:
}

$ftp->quit;
print "END.\n";

#### Second Attempt ##################################################
# Firewall access information
$firewallname="ftpgate.somewhere.com";
$firewalluser="abcuser";
$firewallpassword="userpassword";

# FTP Server address, login and password
$ftpname="ftp2.SomeOtherPlace.com";

$loginname="userxyz";
$password='userxyzpassword';

# Connect to firewall
print "Connecting to $firewallname...";
$ftp=Net::FTP->new ($firewallname, Debug => 1) or errormessage("Can\'t
connect to Firewall $firewallname\n");
print "OK\n";

# Login to firewall
print "Login to firewall as $loginname...";
$ftp->login($firewalluser,$firewallpassword) or errormessage("Can\'t
login as $firewalluser/$firewallpassword- $!\n");
print "OK\n";

# Login to ftp site
print "Follow on Login as $ftpusersite...";
$ftp->command("user $ftpusersite") or errormessage("Can\'t do second
login as user $ftpusersite - $!\n");
print "OK\n";
$ftp->command($password) or errormessage("Can\'t do second login
password as $password - $!\n");
print "OK\n";

#### Complete whatever you will be doing on ftp server. i.e. get put
etc. ####
&messageprint ("Get directory listing of $remotedirname...");

of $remotedirname - $!\n");
&messageprint ("OK\n");

{
  if (substr ($_,0,1) eq "-")                       # download files
  {
    $filesize=substr($_,30)=~/(\d+\.?\d*|\.\d+)/;   # get file size
    $filesize=sprintf "%d",$1;                      # get file size
    $filename=&getfilename($');                     # get file name
(trunc after date)
 print "$filename ($filesize)\n";

  }

Quote:
}

$ftp->quit;
print "END.\n";

Thank You
Don (needs to learn perl more DOH!) Lundgren



Tue, 16 Sep 2003 22:17:57 GMT  
 Using NET::FTP with authenticating proxy
1- you might run this with the Debug flag of Net::FTP set so that we could
see exactly where it fails
2- I have used Net::FTP with the type of proxy you are dealing with. It
wasn't very hard. I looked at the Net::FTP docs and I think you are doing
the wrong thing by attempting to log into your proxy server with the login
method. The docs do state:

http://theoryx5.uwinnipeg.ca/CPAN/data/libnet/Net/FTP.html

that an authorize method is called internally to handle negotiation of the
firewall. The login argument is for getting into the FTP site, *not* the
proxy, per the docs...

What you have to do is configure Net::FTP when you download and install it
(it's in the libnet package) so that it has the uname and passwd for the
proxy in it's internal config file... that is what I did.

Quote:

> I am having a bear of a time with an ftp through a proxy server
> requiring authentication.What we have is a situation where the script is
> running on an NT machine running ActiveState Perl that is doing a ftp
> connection to the firewall with a userid & password once that happens it

> then need to enter the password for the follow on server. I have tried a
> few variations on this and have not had any luck. Each test says that
> all went well but does not return the directory listing. When I run the
> script from outside the firewall and reconfigure it to not use the
> firewall all runs fine and I get my directory listing.

> The ultimate goal is to replace a simple batch file that has no logging
> or error correction with the perl script which will do both. The basic
> commands that the batch file is running are as follows:
>     open ftpgate.somewhere.com
>     abcuser
>     userpassword

>     userxyzpassword
>     < balance of commands ommited to shorten >

> If there is any way I can get you to take a quick look at the scripts
> below and see if anything pops out at you that would be great. What I
> have tried so far is as follows:

> #### First Attempt ##################################################
> # Firewall access information
> $firewallname="ftpgate.somewhere.com";
> $firewalluser="abcuser";
> $firewallpassword="userpassword";

> # FTP Server address, login and password
> $ftpname="ftp2.SomeOtherPlace.com";

> $loginname="userxyz";
> $password='userxyzpassword';

> # Remote directory you wish to download from (SOURCE)
> $remotedirname="/motftp";
> # Connect to firewall
> print "Connecting to $firewallname...";
> $ftp=Net::FTP->new ($firewallname, Debug => 1) or errormessage("Can\'t
> connect to Firewall $firewallname - $!\n");
> print "OK\n";

> # Login to firewall
> print "Login to firewall as $loginname...";
> $ftp->login($firewalluser,$firewallpassword) or errormessage("Can\'t
> login as $firewalluser/$firewallpassword- $!\n");
> print "OK\n";

> # Login to ftp site
> #print "Follow on Login as $ftpusersite...";
> $ftp->user($ftpusersite) or errormessage("Can\'t do second login as
> $ftpusersite - $!\n");
> $ftp->pass($password) or errormessage("Can\'t do second login password
> as $password - $!\n");
> print "OK\n";

> #### Get directory listing for specific directory on follow on machine
> ####
> &messageprint ("Get directory listing of $remotedirname...");

> of $remotedirname - $!\n");
> &messageprint ("OK\n");

> {
>   if (substr ($_,0,1) eq "-")                       # download files
>   {
>     $filesize=substr($_,30)=~/(\d+\.?\d*|\.\d+)/;   # get file size
>     $filesize=sprintf "%d",$1;                      # get file size
>     $filename=&getfilename($');                     # get file name
> (trunc after date)
>  print "$filename ($filesize)\n";

>   }
> }

> $ftp->quit;
> print "END.\n";

> #### Second Attempt ##################################################
> # Firewall access information
> $firewallname="ftpgate.somewhere.com";
> $firewalluser="abcuser";
> $firewallpassword="userpassword";

> # FTP Server address, login and password
> $ftpname="ftp2.SomeOtherPlace.com";

> $loginname="userxyz";
> $password='userxyzpassword';

> # Connect to firewall
> print "Connecting to $firewallname...";
> $ftp=Net::FTP->new ($firewallname, Debug => 1) or errormessage("Can\'t
> connect to Firewall $firewallname\n");
> print "OK\n";

> # Login to firewall
> print "Login to firewall as $loginname...";
> $ftp->login($firewalluser,$firewallpassword) or errormessage("Can\'t
> login as $firewalluser/$firewallpassword- $!\n");
> print "OK\n";

> # Login to ftp site
> print "Follow on Login as $ftpusersite...";
> $ftp->command("user $ftpusersite") or errormessage("Can\'t do second
> login as user $ftpusersite - $!\n");
> print "OK\n";
> $ftp->command($password) or errormessage("Can\'t do second login
> password as $password - $!\n");
> print "OK\n";

> #### Complete whatever you will be doing on ftp server. i.e. get put
> etc. ####
> &messageprint ("Get directory listing of $remotedirname...");

> of $remotedirname - $!\n");
> &messageprint ("OK\n");

> {
>   if (substr ($_,0,1) eq "-")                       # download files
>   {
>     $filesize=substr($_,30)=~/(\d+\.?\d*|\.\d+)/;   # get file size
>     $filesize=sprintf "%d",$1;                      # get file size
>     $filename=&getfilename($');                     # get file name
> (trunc after date)
>  print "$filename ($filesize)\n";

>   }
> }

> $ftp->quit;
> print "END.\n";

> Thank You
> Don (needs to learn perl more DOH!) Lundgren


--
Terrence Brannon
Oracle Corporation
500 Oracle Parkway
M/S 3op1556a
Redwood Shores, CA 94065
(650) 607-5482


Wed, 17 Sep 2003 00:59:51 GMT  
 Using NET::FTP with authenticating proxy
I did get it working. What I found was that I needed to do two logins.
Apparently when I tried that the first time I must have had something else
wrong because after I went in and recreated the 2 login script it ran fine...
Boy do I feel dumb... Hey maybe too much caffine that day...

The script that works with this kind of firewall is as follows:

# Firewall access information
$firewallname="ftpgate0.somewhere.com";
$firewalluser="someuser";
$firewallpassword="someuserpassword";

# FTP Server address, login and password

$password="otheruserpassword";

open (STDERR,">$errorreport");
open(FILE,">$localrepfilename");

# Connect to firewall
print "Connecting to $firewallname...";
$ftp=Net::FTP->new ($firewallname) or errormessage("Can\'t connect to Firewall

print "OK\n";

# Login to firewall
print "Login to firewall as $loginname...";
$ftp->login($firewalluser,$firewallpassword) or errormessage("Can\'t login as
$firewalluser/$firewallpassword- $!\n");
print "OK\n";

# Login to ftp site
print "Follow on Login as $ftpusersite...";
$ftp->login($ftpusersite,$password) or errormessage("Can\'t login as
$ftpusersite/$password $!\n");
print "OK\n";

####### balance of script omitted ##########

Don Lundgren

Quote:

> 1- you might run this with the Debug flag of Net::FTP set so that we could
> see exactly where it fails
> 2- I have used Net::FTP with the type of proxy you are dealing with. It
> wasn't very hard. I looked at the Net::FTP docs and I think you are doing
> the wrong thing by attempting to log into your proxy server with the login
> method. The docs do state:

> http://theoryx5.uwinnipeg.ca/CPAN/data/libnet/Net/FTP.html

> that an authorize method is called internally to handle negotiation of the
> firewall. The login argument is for getting into the FTP site, *not* the
> proxy, per the docs...

> What you have to do is configure Net::FTP when you download and install it
> (it's in the libnet package) so that it has the uname and passwd for the
> proxy in it's internal config file... that is what I did.


> > I am having a bear of a time with an ftp through a proxy server
> > requiring authentication.What we have is a situation where the script is
> > running on an NT machine running ActiveState Perl that is doing a ftp
> > connection to the firewall with a userid & password once that happens it

> > then need to enter the password for the follow on server. I have tried a
> > few variations on this and have not had any luck. Each test says that
> > all went well but does not return the directory listing. When I run the
> > script from outside the firewall and reconfigure it to not use the
> > firewall all runs fine and I get my directory listing.

> > The ultimate goal is to replace a simple batch file that has no logging
> > or error correction with the perl script which will do both. The basic
> > commands that the batch file is running are as follows:
> >     open ftpgate.somewhere.com
> >     abcuser
> >     userpassword

> >     userxyzpassword
> >     < balance of commands ommited to shorten >

> > If there is any way I can get you to take a quick look at the scripts
> > below and see if anything pops out at you that would be great. What I
> > have tried so far is as follows:

> > #### First Attempt ##################################################
> > # Firewall access information
> > $firewallname="ftpgate.somewhere.com";
> > $firewalluser="abcuser";
> > $firewallpassword="userpassword";

> > # FTP Server address, login and password
> > $ftpname="ftp2.SomeOtherPlace.com";

> > $loginname="userxyz";
> > $password='userxyzpassword';

> > # Remote directory you wish to download from (SOURCE)
> > $remotedirname="/motftp";
> > # Connect to firewall
> > print "Connecting to $firewallname...";
> > $ftp=Net::FTP->new ($firewallname, Debug => 1) or errormessage("Can\'t
> > connect to Firewall $firewallname - $!\n");
> > print "OK\n";

> > # Login to firewall
> > print "Login to firewall as $loginname...";
> > $ftp->login($firewalluser,$firewallpassword) or errormessage("Can\'t
> > login as $firewalluser/$firewallpassword- $!\n");
> > print "OK\n";

> > # Login to ftp site
> > #print "Follow on Login as $ftpusersite...";
> > $ftp->user($ftpusersite) or errormessage("Can\'t do second login as
> > $ftpusersite - $!\n");
> > $ftp->pass($password) or errormessage("Can\'t do second login password
> > as $password - $!\n");
> > print "OK\n";

> > #### Get directory listing for specific directory on follow on machine
> > ####
> > &messageprint ("Get directory listing of $remotedirname...");

> > of $remotedirname - $!\n");
> > &messageprint ("OK\n");

> > {
> >   if (substr ($_,0,1) eq "-")                       # download files
> >   {
> >     $filesize=substr($_,30)=~/(\d+\.?\d*|\.\d+)/;   # get file size
> >     $filesize=sprintf "%d",$1;                      # get file size
> >     $filename=&getfilename($');                     # get file name
> > (trunc after date)
> >  print "$filename ($filesize)\n";

> >   }
> > }

> > $ftp->quit;
> > print "END.\n";

> > #### Second Attempt ##################################################
> > # Firewall access information
> > $firewallname="ftpgate.somewhere.com";
> > $firewalluser="abcuser";
> > $firewallpassword="userpassword";

> > # FTP Server address, login and password
> > $ftpname="ftp2.SomeOtherPlace.com";

> > $loginname="userxyz";
> > $password='userxyzpassword';

> > # Connect to firewall
> > print "Connecting to $firewallname...";
> > $ftp=Net::FTP->new ($firewallname, Debug => 1) or errormessage("Can\'t
> > connect to Firewall $firewallname\n");
> > print "OK\n";

> > # Login to firewall
> > print "Login to firewall as $loginname...";
> > $ftp->login($firewalluser,$firewallpassword) or errormessage("Can\'t
> > login as $firewalluser/$firewallpassword- $!\n");
> > print "OK\n";

> > # Login to ftp site
> > print "Follow on Login as $ftpusersite...";
> > $ftp->command("user $ftpusersite") or errormessage("Can\'t do second
> > login as user $ftpusersite - $!\n");
> > print "OK\n";
> > $ftp->command($password) or errormessage("Can\'t do second login
> > password as $password - $!\n");
> > print "OK\n";

> > #### Complete whatever you will be doing on ftp server. i.e. get put
> > etc. ####
> > &messageprint ("Get directory listing of $remotedirname...");

> > of $remotedirname - $!\n");
> > &messageprint ("OK\n");

> > {
> >   if (substr ($_,0,1) eq "-")                       # download files
> >   {
> >     $filesize=substr($_,30)=~/(\d+\.?\d*|\.\d+)/;   # get file size
> >     $filesize=sprintf "%d",$1;                      # get file size
> >     $filename=&getfilename($');                     # get file name
> > (trunc after date)
> >  print "$filename ($filesize)\n";

> >   }
> > }

> > $ftp->quit;
> > print "END.\n";

> > Thank You
> > Don (needs to learn perl more DOH!) Lundgren

> --
> Terrence Brannon
> Oracle Corporation
> 500 Oracle Parkway
> M/S 3op1556a
> Redwood Shores, CA 94065
> (650) 607-5482



Mon, 22 Sep 2003 05:09:25 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Using NET::FTP with authenticating proxy

2. using Net::FTP through a *w3* proxy

3. Using Net::FTP with a socks proxy server

4. Net::SSLeay post requests and authenticating proxy

5. Authenticating proxy requests over SSL - Net::SSLeay???

6. Net::FTP - configure ftp proxy

7. Net::FTP - configure my ftp proxy

8. Cannot get authenticated to Yahoo's SMTP servers while sending mail using Net::SMTP

9. (Perl) WWW-Authenticate: NTLM using LWP::* or Net::* ???

10. Problems with Net::FTP and proxy

11. Net::FTP - proxy trouble.

12. Net::FTP and proxies

 

 
Powered by phpBB® Forum Software