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.



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

#netftpObject (readonly)

Returns the value of attribute netftp.



45
46
47
# File 'lib/rio/ftp/dir.rb', line 45

def netftp
  @netftp
end

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

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

#closeObject



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

#namesObject



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

#readObject



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_pathObject



62
63
64
# File 'lib/rio/ftp/dir.rb', line 62

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

#url_rootObject



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