Class: Photocopier::FTP::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/photocopier/ftp/session.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Session

Returns a new instance of Session.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/photocopier/ftp/session.rb', line 4

def initialize(options)
  @scheme = options[:scheme]

  @session = if sftp?
               Net::SFTP.start(
                 options[:host],
                 options[:user],
                 password: options[:password],
                 port: options[:port] || 22
               )
             else
               Net::FTP.open(
                 options[:host],
                 username: options[:user],
                 password: options[:password],
                 port: options[:port] || 21,
                 passive: options[:passive] || false,
                 ssl: @scheme == 'ftps' && true || false
               )
             end
end

Instance Method Details

#delete(remote) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/photocopier/ftp/session.rb', line 42

def delete(remote)
  if sftp?
    @session.remove!(remote)
  else
    @session.delete(remote)
  end
end

#get(remote, local) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/photocopier/ftp/session.rb', line 26

def get(remote, local)
  if sftp?
    @session.download!(remote, local)
  else
    @session.get(remote, local)
  end
end

#put_file(local, remote) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/photocopier/ftp/session.rb', line 34

def put_file(local, remote)
  if sftp?
    @session.upload!(local, remote)
  else
    @session.put(local, remote)
  end
end