Class: Rftp
- Inherits:
-
Object
- Object
- Rftp
- Defined in:
- lib/rftp.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
- #[](num) ⇒ Object
- #collect(&block) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(options) ⇒ Rftp
constructor
A new instance of Rftp.
- #ls(path = ".") ⇒ Object
Constructor Details
#initialize(options) ⇒ Rftp
Returns a new instance of Rftp.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/rftp.rb', line 115 def initialize() .rftp_symbolize_keys begin self.connection = Net::FTP.new [:host] rescue SocketError => socket_error raise "Unable to connect to #{[:host]}. #{socket_error}" end begin if [:username] && [:password] self.connection.login [:username], [:password] else self.connection.login end rescue Net::FTPPermError => error raise "Unable to login to #{[:host]}. #{error}" end if [:passive] self.connection.passive = true end self.root = self.connection.pwd end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
113 114 115 |
# File 'lib/rftp.rb', line 113 def connection @connection end |
#root ⇒ Object
Returns the value of attribute root.
113 114 115 |
# File 'lib/rftp.rb', line 113 def root @root end |
Instance Method Details
#[](num) ⇒ Object
153 154 155 |
# File 'lib/rftp.rb', line 153 def [](num) ls[num] end |
#collect(&block) ⇒ Object
147 148 149 150 151 |
# File 'lib/rftp.rb', line 147 def collect(&block) ls.collect do |file| yield file end end |
#each(&block) ⇒ Object
141 142 143 144 145 |
# File 'lib/rftp.rb', line 141 def each(&block) ls.each do |file| yield file end end |
#ls(path = ".") ⇒ Object
157 158 159 160 |
# File 'lib/rftp.rb', line 157 def ls(path = ".") self.connection.chdir path RftpDirectory.new(self.root, self, self.connection.ls("-T")) end |