Class: APDM::Saxo::Remote
- Inherits:
-
Object
- Object
- APDM::Saxo::Remote
- Defined in:
- lib/apdm/saxo/remote.rb
Instance Attribute Summary collapse
-
#local_size ⇒ Object
Returns the value of attribute local_size.
-
#photo ⇒ Object
Returns the value of attribute photo.
-
#remote_size ⇒ Object
Returns the value of attribute remote_size.
-
#saxo ⇒ Object
Returns the value of attribute saxo.
Instance Method Summary collapse
- #cleanup(ftp) ⇒ Object
- #destination ⇒ Object
-
#initialize(saxo, photo) ⇒ Remote
constructor
A new instance of Remote.
- #logger ⇒ Object
- #source ⇒ Object
- #transfer ⇒ Object
- #transfer_succeeded? ⇒ Boolean
- #upload(ftp) ⇒ Object
Constructor Details
#initialize(saxo, photo) ⇒ Remote
Returns a new instance of Remote.
9 10 11 12 |
# File 'lib/apdm/saxo/remote.rb', line 9 def initialize(saxo, photo) self.saxo = saxo self.photo = photo end |
Instance Attribute Details
#local_size ⇒ Object
Returns the value of attribute local_size.
8 9 10 |
# File 'lib/apdm/saxo/remote.rb', line 8 def local_size @local_size end |
#photo ⇒ Object
Returns the value of attribute photo.
8 9 10 |
# File 'lib/apdm/saxo/remote.rb', line 8 def photo @photo end |
#remote_size ⇒ Object
Returns the value of attribute remote_size.
8 9 10 |
# File 'lib/apdm/saxo/remote.rb', line 8 def remote_size @remote_size end |
#saxo ⇒ Object
Returns the value of attribute saxo.
8 9 10 |
# File 'lib/apdm/saxo/remote.rb', line 8 def saxo @saxo end |
Instance Method Details
#cleanup(ftp) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/apdm/saxo/remote.rb', line 49 def cleanup(ftp) if transfer_succeeded? File.delete(source) else ftp.delete(destination) end end |
#destination ⇒ Object
22 23 24 |
# File 'lib/apdm/saxo/remote.rb', line 22 def destination @destination ||= "#{saxo.remote_dir}/#{photo.name}" end |
#logger ⇒ Object
14 15 16 |
# File 'lib/apdm/saxo/remote.rb', line 14 def logger APDM::Saxo.logger end |
#source ⇒ Object
18 19 20 |
# File 'lib/apdm/saxo/remote.rb', line 18 def source @source ||= photo.file end |
#transfer ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/apdm/saxo/remote.rb', line 26 def transfer logger.info("Begin transfer of #{source} to #{destination}") Timeout.timeout(30) do Net::FTP.open(saxo.server, saxo.username, saxo.password) do |ftp| Timeout.timeout(20) do upload(ftp) end Timeout.timeout(10) do cleanup(ftp) end end end return true if transfer_succeeded? raise SaxoTransferError("Upload failed [#{local_size}/#{remote_size}]. Source: #{source} -- destination: #{destination}") end |
#transfer_succeeded? ⇒ Boolean
57 58 59 |
# File 'lib/apdm/saxo/remote.rb', line 57 def transfer_succeeded? local_size == remote_size end |
#upload(ftp) ⇒ Object
43 44 45 46 47 |
# File 'lib/apdm/saxo/remote.rb', line 43 def upload(ftp) ftp.passive = true ftp.putbinaryfile(source, destination) self.remote_size = ftp.size(destination) end |