develooper Front page | perl.libwww | Postings from November 2001

Net::FTP and list remote files

Thread Next
From:
Manuel de la =?iso-8859-1?Q?Herr=E1n=20Gasc=F3n?=
Date:
November 6, 2001 01:54
Subject:
Net::FTP and list remote files
Message ID:
3BE7B33C.29FB5DAB@cocotero.com
Hi list!

I've made those functions than run fine with Perl and MS-DOS to
download/upload files from/to Unix machines.

How can I use Net::FTP to list remote files? I'd like to control
overriting as I do with local ones. Is there something like $ftp->ls?

Thanks a lot

#
-----------------------------------------------------------------------
sub uploadAuthRemoteFile {
  (my $transferDebug, my $transferMode, my $transferReplace, my
$remoteServerDomain, my $remoteServerUser, my $remoteServerPass, my
$remoteServerFileName, my $localFileToPut) = @_;
  use Net::FTP;
  my $remoteServerPath = "";
  if (&fExistsFile($localFileToPut) eq "True") {
    my $ftp = Net::FTP->new($remoteServerDomain, Debug =>
$transferDebug, Passive => 1);
    $ftp->login($remoteServerUser, $remoteServerPass);
    if ($remoteServerFileName =~ m/^(.*)\/(.*?)$/) {
      $remoteServerPath = $1;
      $remoteServerFileName = $2;
      $ftp->cwd($remoteServerPath);
      if ($transferMode eq "bin") {
        $ftp->binary;
      }
    } else {
      print "Error: $remoteServerFileName\n";
    }
    $ftp->put($localFileToPut, $remoteServerFileName);
    $ftp->quit;
    print "Uploaded: " . $remoteServerFileName . "\n";
  } else {
    print "Error: Not local file ol folder $localFileToPut\n";
  }
  return $localFileToPut;
}
#
-----------------------------------------------------------------------
sub downloadAuthRemoteFile {
  (my $transferDebug, my $transferMode, my $transferReplace, my
$remoteServerDomain, my $remoteServerUser, my $remoteServerPass, my
$remoteServerFileName, my $localFileToWrite) = @_;
  use Net::FTP;
  my $remoteServerPath = "";
  if ($transferReplace eq "replace" or &fExistsFile($localFileToWrite)
eq "False") {
    my $ftp = Net::FTP->new($remoteServerDomain, Debug =>
$transferDebug, Passive => 1);
    if ($remoteServerUser eq "" or $remoteServerPass eq "") {
      print "Error: " . $remoteServerUser . "-" . $remoteServerPass;
    }
    $ftp->login($remoteServerUser, $remoteServerPass);
    if ($remoteServerFileName =~ m/^(.*)\/(.*?)$/) {
      $remoteServerPath = $1;
      $remoteServerFileName = $2;
      $ftp->cwd($remoteServerPath);
      if ($transferMode eq "bin") {
        $ftp->binary;
      }
    } else {
      print "Error: $remoteServerFileName\n";
    }
    $ftp->get($remoteServerFileName, $localFileToWrite);
    $ftp->quit;
    if (&fExistsFile($localFileToWrite) eq "True") {
      print "Downloaded: " . $localFileToWrite . "\n";
    } else {
      print "Not in the server, not local folder or bad password (Not
downloaded): " . $remoteServerFileName . "\n";
    }
  } else {
    print "Already exists (Not downloaded): " . $localFileToWrite .
"\n";
  }
  return $localFileToWrite;
}
#
-----------------------------------------------------------------------


--
Manuel de la Herrán Gascón
Tel: 91-5488449
Fax: 91-5488459
manu@cocotero.com
http://www.cocotero.com/




Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About