Class: IamFtp::FtpCalls
- Inherits:
-
Object
- Object
- IamFtp::FtpCalls
- Defined in:
- lib/iam_ftp.rb
Class Attribute Summary collapse
-
.logger ⇒ Object
Returns the value of attribute logger.
Instance Attribute Summary collapse
-
#ftp_host ⇒ Object
Returns the value of attribute ftp_host.
-
#ftp_password ⇒ Object
Returns the value of attribute ftp_password.
-
#ftp_username ⇒ Object
Returns the value of attribute ftp_username.
Instance Method Summary collapse
- #ftp_close ⇒ Object
- #ftp_connect ⇒ Object
- #get_ready_and_upload_the_file(local_file_path, remote_file_path, filename) ⇒ Object
-
#initialize(ftp_info_hash) ⇒ FtpCalls
constructor
A new instance of FtpCalls.
- #is_ftp_file?(ftp, file_name) ⇒ Boolean
- #list_all_files ⇒ Object
- #upload_directory_to_ftp_server(local_file_path, remote_file_path) ⇒ Object
- #upload_file_to_ftp_server(local_file_path, remote_file_path, filename) ⇒ Object
Constructor Details
#initialize(ftp_info_hash) ⇒ FtpCalls
Returns a new instance of FtpCalls.
15 16 17 18 19 20 |
# File 'lib/iam_ftp.rb', line 15 def initialize(ftp_info_hash) @ftp_host = ftp_info_hash[:ftp_host].to_s @ftp_username = ftp_info_hash[:ftp_username].to_s @ftp_password = ftp_info_hash[:ftp_password].to_s @connection = nil end |
Class Attribute Details
.logger ⇒ Object
Returns the value of attribute logger.
12 13 14 |
# File 'lib/iam_ftp.rb', line 12 def logger @logger end |
Instance Attribute Details
#ftp_host ⇒ Object
Returns the value of attribute ftp_host.
9 10 11 |
# File 'lib/iam_ftp.rb', line 9 def ftp_host @ftp_host end |
#ftp_password ⇒ Object
Returns the value of attribute ftp_password.
9 10 11 |
# File 'lib/iam_ftp.rb', line 9 def ftp_password @ftp_password end |
#ftp_username ⇒ Object
Returns the value of attribute ftp_username.
9 10 11 |
# File 'lib/iam_ftp.rb', line 9 def ftp_username @ftp_username end |
Instance Method Details
#ftp_close ⇒ Object
30 31 32 33 |
# File 'lib/iam_ftp.rb', line 30 def ftp_close puts "Connection closing.." @connection.close end |
#ftp_connect ⇒ Object
23 24 25 26 27 |
# File 'lib/iam_ftp.rb', line 23 def ftp_connect @connection = Net::FTP.new(ftp_host) @connection.passive =true @connection.login(ftp_username, ftp_password) end |
#get_ready_and_upload_the_file(local_file_path, remote_file_path, filename) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/iam_ftp.rb', line 66 def get_ready_and_upload_the_file(local_file_path, remote_file_path, filename) filename.gsub!("#{local_file_path}/", '') local = File.join local_file_path, filename remote = "#{remote_file_path}/#{filename}".gsub(/\/+/, '/') if File.directory?(local) @connection.mkdir remote rescue Net::FTPPermError puts "Created Remote Directory #{local}" elsif File.file?(local) @connection.putbinaryfile local, remote puts "Pushed file #{remote}" end end |
#is_ftp_file?(ftp, file_name) ⇒ Boolean
56 57 58 59 60 61 62 63 64 |
# File 'lib/iam_ftp.rb', line 56 def is_ftp_file?(ftp, file_name) ftp.chdir(file_name) ftp.chdir('..') false rescue true end |
#list_all_files ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/iam_ftp.rb', line 36 def list_all_files Net::FTP.open(ftp_host) do |ftp| ftp.login(ftp_username, ftp_password ) ftp.passive = true a = ftp.nlst b = ftp.nlst('**/*.*') c = ftp.nlst('**/**/*.*') d = ftp.nlst('**/**/**/*.*') e = ftp.nlst('**/**/**/**/*.*') ftp.close file_list = a+ b + c + d + e file_list end end |
#upload_directory_to_ftp_server(local_file_path, remote_file_path) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/iam_ftp.rb', line 82 def upload_directory_to_ftp_server(local_file_path, remote_file_path) ftp_connect Dir.glob(File.join(local_file_path, '**', '*')) do |filename| get_ready_and_upload_the_file(local_file_path, remote_file_path, filename) end ftp_close end |
#upload_file_to_ftp_server(local_file_path, remote_file_path, filename) ⇒ Object
94 95 96 |
# File 'lib/iam_ftp.rb', line 94 def upload_file_to_ftp_server(local_file_path, remote_file_path, filename) get_ready_and_upload_the_file(local_file_path, remote_file_path, filename) end |