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
# File 'lib/photocopier/ftp/session.rb', line 4

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

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

Instance Method Details

#delete(remote) ⇒ Object



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

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

#get(remote, local) ⇒ Object



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

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

#put_file(local, remote) ⇒ Object



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

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