Class: RIO::FTP::Dir::Stream
Instance Attribute Summary collapse
-
#netftp ⇒ Object
readonly
Returns the value of attribute netftp.
-
#remote_root ⇒ Object
readonly
Returns the value of attribute remote_root.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #close ⇒ Object
- #each(&block) ⇒ Object
- #entpath(ent) ⇒ Object
-
#initialize(uri) ⇒ Stream
constructor
A new instance of Stream.
- #names ⇒ Object
- #read ⇒ Object
- #remote_path ⇒ Object
- #url_root ⇒ Object
Constructor Details
#initialize(uri) ⇒ Stream
Returns a new instance of Stream.
46 47 48 49 50 51 52 53 |
# File 'lib/rio/ftp/dir.rb', line 46 def initialize(uri) @uri = uri.clone @conn = ConnCache.instance.connect(uri) @remote_root = @conn.remote_root @remote_root = '' if @remote_root == '/' @names = nil @entidx = 0 end |
Instance Attribute Details
#netftp ⇒ Object (readonly)
Returns the value of attribute netftp.
45 46 47 |
# File 'lib/rio/ftp/dir.rb', line 45 def netftp @netftp end |
#remote_root ⇒ Object (readonly)
Returns the value of attribute remote_root.
45 46 47 |
# File 'lib/rio/ftp/dir.rb', line 45 def remote_root @remote_root end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
45 46 47 |
# File 'lib/rio/ftp/dir.rb', line 45 def uri @uri end |
Instance Method Details
#close ⇒ Object
59 60 61 |
# File 'lib/rio/ftp/dir.rb', line 59 def close() ConnCache.instance.close(uri) end |
#each(&block) ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/rio/ftp/dir.rb', line 83 def each(&block) p "Hello Mr. Phelps" names.each { |ent| @entidx += 1 yield entpath(ent) } self end |
#entpath(ent) ⇒ Object
72 73 74 |
# File 'lib/rio/ftp/dir.rb', line 72 def entpath(ent) ent.sub(/^#{remote_path}/,'') end |
#names ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/rio/ftp/dir.rb', line 65 def names() @names ||= begin @conn.nlst(remote_path()) rescue ::Net::FTPPermError [] end end |
#read ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/rio/ftp/dir.rb', line 75 def read() name = names[@entidx] if name rtn = entpath(name) @entidx +=1 rtn end end |
#remote_path ⇒ Object
62 63 64 |
# File 'lib/rio/ftp/dir.rb', line 62 def remote_path() self.remote_root+@uri.path end |
#url_root ⇒ Object
54 55 56 57 58 |
# File 'lib/rio/ftp/dir.rb', line 54 def url_root() root_uri = @uri.clone root_uri.path = '' root_uri.to_s end |