Class: EventMachine::FtpClient::Session
- Inherits:
-
Object
- Object
- EventMachine::FtpClient::Session
- Defined in:
- lib/em-ftp-client/session.rb
Overview
Main class for interacting with a server
Instance Attribute Summary collapse
-
#control_connection ⇒ Object
readonly
Returns the value of attribute control_connection.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #close ⇒ Object
- #cwd(dir, &cb) ⇒ Object
- #get(file, &cb) ⇒ Object
-
#initialize(url, options = {}, &cb) ⇒ Session
constructor
A new instance of Session.
- #list(&cb) ⇒ Object
- #put(file, &cb) ⇒ Object
- #pwd(&cb) ⇒ Object
- #stream(&cb) ⇒ Object
Constructor Details
#initialize(url, options = {}, &cb) ⇒ Session
Returns a new instance of Session.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/em-ftp-client/session.rb', line 9 def initialize(url, ={}, &cb) self.username = [:username] || "anonymous" self.password = [:password] || "anonymous" self.port = [:port] || 21 @control_connection = EM.connect(url, port, ControlConnection) @control_connection.username = username @control_connection.password = password @control_connection.callback do cb.call(self) end end |
Instance Attribute Details
#control_connection ⇒ Object (readonly)
Returns the value of attribute control_connection.
7 8 9 |
# File 'lib/em-ftp-client/session.rb', line 7 def control_connection @control_connection end |
#password ⇒ Object
Returns the value of attribute password.
5 6 7 |
# File 'lib/em-ftp-client/session.rb', line 5 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
5 6 7 |
# File 'lib/em-ftp-client/session.rb', line 5 def port @port end |
#username ⇒ Object
Returns the value of attribute username.
5 6 7 |
# File 'lib/em-ftp-client/session.rb', line 5 def username @username end |
Instance Method Details
#close ⇒ Object
61 62 63 64 65 66 |
# File 'lib/em-ftp-client/session.rb', line 61 def close @control_connection.callback do yield if block_given? end @control_connection.close end |
#cwd(dir, &cb) ⇒ Object
27 28 29 30 |
# File 'lib/em-ftp-client/session.rb', line 27 def cwd(dir, &cb) control_connection.callback(&cb) control_connection.cwd(dir) end |
#get(file, &cb) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/em-ftp-client/session.rb', line 42 def get(file, &cb) control_connection.callback do |data_connection| data_connection.stream(&@stream) if @stream control_connection.callback(&cb) control_connection.retr file end control_connection.pasv end |
#list(&cb) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/em-ftp-client/session.rb', line 32 def list(&cb) control_connection.callback do control_connection.callback(&cb) control_connection.list end control_connection.pasv end |
#put(file, &cb) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/em-ftp-client/session.rb', line 51 def put(file, &cb) filename = File.basename(file) control_connection.callback do |data_connection| data_connection.send_file(file) control_connection.callback(&cb) control_connection.stor filename end control_connection.pasv end |
#pwd(&cb) ⇒ Object
22 23 24 25 |
# File 'lib/em-ftp-client/session.rb', line 22 def pwd(&cb) control_connection.callback(&cb) control_connection.pwd end |
#stream(&cb) ⇒ Object
40 |
# File 'lib/em-ftp-client/session.rb', line 40 def stream(&cb); @stream = cb; end |