Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Get names of files ONLY using module Net::SFTP::Foreign
Hi all,


I am a newbie in this forum and Perl too ;-)

I am trying writing script transfering files using module
Net::SFTP::Foreign.

I need to retrieve from remote directory only names of files (not
directories, links,etc.).

Something like this doesn't work:

--------------
use strict;
use warnings;
use Net::SFTP::Foreign;

my $remote_dir = "/tmp";
my $sftp = Net::SFTP::Foreign->new("host");
$sftp->error and print "SSH connection failed: " . $sftp->error . "\n";

$sftp->setcwd($remote_dir);
my $DH = $sftp->opendir($remote_dir);
while ($_ = $sftp->readdir($DH)) {
print "$_->{filename} \n" if -f $_->{filename};
}
---------------

Script above write out nothing, but if last line is this

print "$_->{filename} \n";

It writes out names of files, directories, but I need only names of files.
How can I get it easy?

Thanks.

Marian


Report this thread to moderator Post Follow-up to this message
Old Post
Marian Bednar
08-25-07 12:01 AM


Re: Get names of files ONLY using module Net::SFTP::Foreign
On Friday 24 August 2007 08:57:26 Marian Bednar wrote:
> Hi all,
>
>
> I am a newbie in this forum and Perl too ;-)
>
> I am trying writing script transfering files using module
> Net::SFTP::Foreign.
>
> I need to retrieve from remote directory only names of files (not
> directories, links,etc.).
>
> Something like this doesn't work:
>
> --------------
> use strict;
> use warnings;
> use Net::SFTP::Foreign;
>
> my $remote_dir = "/tmp";
> my $sftp = Net::SFTP::Foreign->new("host");
> $sftp->error and print "SSH connection failed: " . $sftp->error . "\n";
>
> $sftp->setcwd($remote_dir);
> my $DH = $sftp->opendir($remote_dir);
> while ($_ = $sftp->readdir($DH)) {
> print "$_->{filename} \n" if -f $_->{filename};
> }
> ---------------
>
> Script above write out nothing, but if last line is this
>
> print "$_->{filename} \n";
>
> It writes out names of files, directories, but I need only names of files.
> How can I get it easy?
>
> Thanks.
>
> Marian

You cannot use -f. You'll need to stat the file and check the mode.

Report this thread to moderator Post Follow-up to this message
Old Post
Stephen Kratzer
08-25-07 12:01 AM


Re: Get names of files ONLY using module Net::SFTP::Foreign
Stephen Kratzer wrote:
> On Friday 24 August 2007 08:57:26 Marian Bednar wrote: 
>
> You cannot use -f. You'll need to stat the file and check the mode.

-f *does* stat the file.  The reason that you can't use -f (or stat) is
because $_->{filename} is not on a locally mounted file system.



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

Report this thread to moderator Post Follow-up to this message
Old Post
John W. Krahn
08-25-07 02:59 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:50 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.