Hi,

You need to use:

$ftp->get("/path/to/remote/file", "/path/to/local/destination_file");

Octavian

----- Original Message ----- From: <[EMAIL PROTECTED]>
To: <beginners@perl.org>
Sent: Wednesday, June 27, 2007 11:59 AM
Subject: [PERL] Net::SFTP functions


Hi all,

I am using Net::SFTP package to remotely connect to a local SFTP
server (on a LAN) and retreive files from it toward another LAN shared
folder.

I am successfully connecting to the SFTP server (of that I am shure as
the $sftp->ls() function displays me the folders of the home
directory) however I have some problems to move through the folders
and retreive files.

I am trying to retreive a file stored in a subfolder of the home
directory but:
1) I did not find a way to move to that folder. There is no "cd"
command with SFTP package ?? I did not find anything in the cpan doc.

2) The file is never retreived when using the $sftp->get() function. I
systematically get the error message "No such file or directory". I
tried virtual pathes, absolute pathes but nothing works :(

Here is my script:

   #Paramètres de connexion
   my $host = xx.xx.xxx.xxx';
   my %args = (user => "toto",
               password  =>  "pass",
               ssh_args  =>  [port=>22]);

   #Création de l'en tête de la requête
   my $sftp = Net::SFTP->new($host, %args) or die "Cannot connect to
$@";
   print "Connected.\n";

   #Récupération de la date du jour
   my $dateJour =  formatDate();

   $sftp->ls('.' , sub { print $_[0]->{filename}, "\n" });

   #On se positionne dans le répertoire
   $sftp->get("rep/Export.csv", "\\\\share\\Exports Annuaires\\Export
$dateJour.csv")
       or die "Impossible de copier le fichier. Error : $!\n";

In the script, I display the folders of the home directory, which is
working (as explained earlier). But if I try  to display the files
stored in the subfolder, I get the same folder listing: I don't
understand.

This folder is called rep, and that is the folder from where I am
trying to retreive a file when I call the get function. My shared
folder is available as the destination file is correctly created
(Export 2007 06 27.csv for example) but allways empty.

And I am working on windows ;)

Am I doing something wrong ? Could someone help me ?

Thanks !


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to