Class: RIO::FTP::Dir::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/rio/ftp/dir.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#netftpObject (readonly)

Returns the value of attribute netftp.



34
35
36
# File 'lib/rio/ftp/dir.rb', line 34

def netftp
  @netftp
end

#remote_rootObject (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

#uriObject (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

#closeObject



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

#namesObject



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

#readObject



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_pathObject



51
52
53
# File 'lib/rio/ftp/dir.rb', line 51

def remote_path()
  self.remote_root+@uri.path
end

#url_rootObject



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