On Sun, Aug 14, 2011 at 5:06 PM, S=F6nke Buhr <sonke / webperator.de> wrote:
> =A0 =A0Net::SFTP.start("somehost", "someuser", :password =3D> "somepwd",
> :keys =3D> []) do |sftp|
> =A0 =A0 =A0sftp.dir.foreach("/upload/") do |e|
>
> What I want to do is to only parse the files in this given directory
> which include "findme" and "foundme" for example.
>
> Is there any way to do this via sftp?

Net::SFTP does have a glob method[1]

(with a "scary" disclaimer: "don=91t expect this method to perform with
the same level of alacrity that ::Dir.glob does; it will work best for
shallow directory hierarchies with relatively few directories, though
it should be able to handle modest numbers of files in each
directory")

The implementation[2] is very much like 7stud's suggestion (loop
through all the names and either select or reject) which may the best
option available:

"SCP allows you to use Unix wild cards in the file name when grab=ADbing
a file from the remote machine. SFTP, on the other hand, expects the
full explicit path to the file you want to down=ADload."[3]

The implementation to support globbing in JSch is similar[4]

[1] http://net-ssh.github.com/sftp/v2/api/classes/Net/SFTP/Operations/Dir.h=
tml#M000012
[2] https://github.com/net-ssh/net-sftp/blob/master/lib/net/sftp/operations=
/dir.rb#L58
[3] http://jessenoller.com/2009/02/05/ssh-programming-with-paramiko-complet=
ely-different/
[4] https://github.com/ePaul/jsch-documentation/blob/master/src/com/jcraft/=
jsch/ChannelSftp.java#L1694