Re: [Ssh-sftp-perl-users] About sftp->ls method
Brought to you by:
dbrobins
From: Russ B. <us...@gm...> - 2008-07-07 15:33:59
|
I use this: @$files_in_directory = $sftp->ls($remote_server_directory); foreach (@$files_in_directory) { $longlist = $_->{longname}; $shortname = $_->{filename}; print "longname = $longname}\n"; print "shortname = $shortname\n"; if ($shortname =~ /txt/) { push @arrivals, $shortname; } } Then sort @arrivals any way you want. Hope this helps. Russ On Mon, Jul 7, 2008 at 8:20 AM, Heiko Jansen <ja...@hb...> wrote: > > Am Montag, den 07.07.2008, 17:29 +0530 schrieb Rajnikant: > > > > > I'm using sftp->ls method to see files on remote location. Following > > files are present on remote location: > > 5.txt, 4.txt, 3.txt, 2.txt, 1.txt > > > > Is there possibility that I'll get sftp->ls out put as > > 5.txt > > 4.txt > > -- > > -- > > 1.txt > > > > Can I have sorted sftp->ls out put? Out put I want is: > > 1.txt > > -- > > -- > > 4.txt > > 5.txt > > As far as I know, $sftp->ls() (where $sftp IS_A Net::SFTP object) > returns a list of hash references and there are no options of > pre-sorting that list. > But no one stops you from iterating over the list, extracting the names > and sorting them in any way you like. > So the answer to your questions is "yes" - but the way to get there is > possibly not as convenient as you'd hoped ;-) > > Heiko > > PS: Another option would be to use do_opendir($path) and then use a > readdir-loop directly on the dir handle, fetching all filenames and > sorting them afterwards. > > PPS: Yet another method: Use Net::SSH2, execute a shell command ("ls" > with the necessary switches) and capture and parse the output. > > > ------------------------------------------------------------------------- > Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! > Studies have shown that voting for your favorite open source project, > along with a healthy diet, reduces your potential for chronic lameness > and boredom. Vote Now at http://www.sourceforge.net/community/cca08 > _______________________________________________ > Ssh-sftp-perl-users mailing list > Ssh...@li... > https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users > |