Schrift
[thread]2938[/thread]

Problems with Net::SFTP

Leser: 3


<< >> 2 Einträge, 1 Seite
prassito
 2005-05-31 09:47
#29485 #29485
User since
2005-05-31
8 Artikel
BenutzerIn
[default_avatar]
Hi Folks

While working with the Net::SFTP Module of Perl i realized a problem i can't solve.
I have a directory with the following files, i want to download from the remote PC to my local server (at least the xml-Files) with a Perl-Skript using SFTP:

drwxr-xr-x    2 uh       uh           4096   31. Mai 07:38 .
drwxr-xr-x    8 uh       uh           4096   30. Mai 16:21 ..
-rw-r--r--    1 root     root            103   31. Mai 07:38 file_a.xml
-rw-r--r--    1 root     root            230   31. Mai 07:38 file_b.xml
-rw-r--r--    1 root     root           1432  31. Mai 07:37 file_c.xml
-rw-r--r--    1 root     root            674   31. Mai 07:37 file_d.xml


I am able to open the connection and put some files onto the remote server.
But if is try to get my four files i can only see the '.', '..' and randomly one of the XMLs.
Anyone got an idea what's wrong?
Thanks and gratz

prassito


<----zip------->
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#Initialisation
my %hashval;
my %sftp_args = (user =>$ftpuser, password =>$ftppwd);

#Open Connection
$ftp = Net::SFTP->new($ftphost, %sftp_args) || exception("SFTP-Login failed (maybe wrong Username or Password?)");

#List all from the downloadpath
%hashval = $ftp->ls($downloadpath);

#Loop through my result
foreach my $_file (%hashval)
{
   $tmp_in_file = $hashval{$_file}->{"filename"};

#We Skip . and ..
   if ($tmp_in_file eq ".." || $tmp_in_file eq ".")
   {
       next();
   }
   else
  {
       $ftp->get($downloadpath."/".$tmp_in_file, $localpath_in."/".$tmp_in_file);
       $ftp->do_remove($downloadpath."/".$tmp_in_file);
   }
}


edit pq: code-tags hinzugefügt\n\n

<!--EDIT|pq|1117537270-->
renee
 2005-05-31 10:20
#29486 #29486
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
ls does not return a hash, but a list of the entries. Each element of the list contains a reference to a hash. I'm not familiar with the CPAN:Net::SFTP-module, but try the following code:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
my %sftp_args = (user =>$ftpuser, password =>$ftppwd);

#Open Connection
$ftp = Net::SFTP->new($ftphost, %sftp_args) || exception("SFTP-Login failed (maybe wrong Username or Password?)");

#List all from the downloadpath
my @entries = $ftp->ls($downloadpath);

#Loop through my result
foreach my $file (@entries){
  next if($file->{filename} =~ /^\.\.?$/);
  $tmp_in_file = $file->{filename};

  $ftp->get($downloadpath."/".$tmp_in_file, $localpath_in."/".$tmp_in_file);
  $ftp->do_remove($downloadpath."/".$tmp_in_file);
}
\n\n

<!--EDIT|renee|1117520462-->
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/
<< >> 2 Einträge, 1 Seite



View all threads created 2005-05-31 09:47.