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.
35 36 37 38 39 40 41 42 |
# File 'lib/rio/ftp/dir.rb', line 35 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.
34 35 36 |
# File 'lib/rio/ftp/dir.rb', line 34 def netftp @netftp end |
#remote_root ⇒ Object (readonly)
Returns the value of attribute remote_root.
34 35 36 |
# File 'lib/rio/ftp/dir.rb', line 34 def remote_root @remote_root end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
34 35 36 |
# File 'lib/rio/ftp/dir.rb', line 34 def uri @uri end |
Instance Method Details
#close ⇒ Object
48 49 50 |
# File 'lib/rio/ftp/dir.rb', line 48 def close() ConnCache.instance.close(uri) end |
#each(&block) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/rio/ftp/dir.rb', line 72 def each(&block) names.each { |ent| @entidx += 1 yield entpath(ent) } self end |
#entpath(ent) ⇒ Object
61 62 63 |
# File 'lib/rio/ftp/dir.rb', line 61 def entpath(ent) ent.sub(/^#{remote_path}/,'') end |
#names ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/rio/ftp/dir.rb', line 54 def names() @names ||= begin @conn.nlst(remote_path()) rescue ::Net::FTPPermError [] end end |
#read ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/rio/ftp/dir.rb', line 64 def read() name = names[@entidx] if name rtn = entpath(name) @entidx +=1 rtn end end |
#remote_path ⇒ Object
51 52 53 |
# File 'lib/rio/ftp/dir.rb', line 51 def remote_path() self.remote_root+@uri.path end |
#url_root ⇒ Object
43 44 45 46 47 |
# File 'lib/rio/ftp/dir.rb', line 43 def url_root() root_uri = @uri.clone root_uri.path = '' root_uri.to_s end |