Sha256: 392a1b6db503873f828fcc405a9e55d678f37590555d57720c30c45a561c98cf

Contents?: true

Size: 1.88 KB

Versions: 5

Compression:

Stored size: 1.88 KB

Contents

#!/usr/bin/ruby
# MPW is a software to crypt and manage your passwords
# Copyright (C) 2016  Adrien Waksberg <mpw@yae.im>
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

require 'i18n'
require 'net/ftp'
		
module MPW
class FTP

	# Constructor
	# @args: config -> the config
	def initialize(config)
		@host      = config['host']
		@user      = config['user']
		@password  = config['password']
		@path      = config['path']
		@port      = config['port'].instance_of?(Integer) ? 22 : config['port']
	end


	# Connect to server
	def connect
		Net::FTP.open(@host) do |ftp|
			ftp.login(@user, @password)
			break
		end
	rescue Exception => e
		raise "#{I18n.t('error.sync.connection')}\n#{e}"
	end

	# Get data on server
	# @args: file_tmp -> the path where download the file
	def get(file_tmp)
		Net::FTP.open(@host) do |ftp|
			ftp.login(@user, @password)
			ftp.gettextfile(@path, file_tmp)
		end
	rescue Exception => e
		raise "#{I18n.t('error.sync.download')}\n#{e}"
	end

	# Update the remote data
	# @args: file_gpg -> the data to send on server
	def update(file_gpg)
		Net::FTP.open(@host) do |ftp|
			ftp.login(@user, @password)
			ftp.puttextfile(file_gpg, @path)
		end
	rescue Exception => e
		raise "#{I18n.t('error.sync.upload')}\n#{e}"
	end
end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mpw-4.0.0 lib/mpw/sync/ftp.rb
mpw-3.2.1 lib/mpw/sync/ftp.rb
mpw-3.2.0 lib/mpw/sync/ftp.rb
mpw-3.1.0 lib/mpw/sync/ftp.rb
mpw-3.0.0 lib/mpw/sync/ftp.rb