Class: WordpressDeploy::Storage::Ftp
- Inherits:
-
Object
- Object
- WordpressDeploy::Storage::Ftp
- Includes:
- ActionView::Helpers::NumberHelper
- Defined in:
- lib/wordpress_deploy/storage/ftp.rb
Instance Method Summary collapse
-
#close ⇒ Object
If the connection is open, close it Returns true if the connection is closed; false otherwise.
- #destination(new_dest = nil) ⇒ Object
- #host(new_host = nil) ⇒ Object
-
#initialize(&block) ⇒ Ftp
constructor
Create a new instance of the Ftp object.
- #password(new_pass = nil) ⇒ Object
- #port ⇒ Object
- #receive ⇒ Object
- #receive!(path = remote_path) ⇒ Object
- #transmit ⇒ Object
- #transmit! ⇒ Object
- #user(new_user = nil) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Ftp
Create a new instance of the Ftp object
15 16 17 18 19 20 21 22 23 |
# File 'lib/wordpress_deploy/storage/ftp.rb', line 15 def initialize(&block) @host ||= "localhost" @port ||= 21 @user ||= "root" @password ||= "" @destination ||= "/" instance_eval(&block) if block_given? end |
Instance Method Details
#close ⇒ Object
If the connection is open, close it Returns true if the connection is closed; false otherwise
65 66 67 68 69 70 71 |
# File 'lib/wordpress_deploy/storage/ftp.rb', line 65 def close unless ftp.closed? ftp.close return true end return false end |
#destination(new_dest = nil) ⇒ Object
57 58 59 60 |
# File 'lib/wordpress_deploy/storage/ftp.rb', line 57 def destination(new_dest = nil) @destination = new_dest.to_s unless new_dest.nil? @destination end |
#host(new_host = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/wordpress_deploy/storage/ftp.rb', line 25 def host(new_host = nil) unless new_host.nil? match = /(?<host>.*?)(?=:|\z)(:(?<port>\d+))?/.match(new_host.to_s) @host = match[:host].to_s unless match[:host].nil? # Set the port information unless match[:port].nil? @port = match[:port].to_i end # Has port is true; unless a socket was set @has_port = !@has_socket end # return the host @host end |
#password(new_pass = nil) ⇒ Object
52 53 54 55 |
# File 'lib/wordpress_deploy/storage/ftp.rb', line 52 def password(new_pass = nil) @password = new_pass.to_s unless new_pass.nil? @password end |
#port ⇒ Object
43 44 45 |
# File 'lib/wordpress_deploy/storage/ftp.rb', line 43 def port @port end |
#receive ⇒ Object
89 90 91 |
# File 'lib/wordpress_deploy/storage/ftp.rb', line 89 def receive raise NotImplementedError end |
#receive!(path = remote_path) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/wordpress_deploy/storage/ftp.rb', line 93 def receive!(path=remote_path) # Where did it start from pwd = ftp.pwd # Change to the remote path chdir(path) # Get a list of all the files # and directories in the current pwd files = ftp.nlst ftp.pwd # Remove the 'dot' directories files.delete(".") files.delete("..") # Create a relative pathname rel_remote_path = Pathname.new(ftp.pwd).relative_path_from Pathname.new(remote_path) # Loop through each file and directory # found in the current pwd files.each do |file| # Build the file name to save it to local_file = Pathname.new(File.join(Config.wp_dir, rel_remote_path, File.basename(file))).cleanpath.to_s if directory? file Logger.debug "[mkdir] #{local_file}" FileUtils.mkdir_p local_file receive! file else str = "[cp] #{file} (#{self.number_to_human_size(ftp.size(file), precision: 2)})" ftp.getbinaryfile(file, local_file) Logger.debug str end end # Return from whence we came chdir(pwd) end |
#transmit ⇒ Object
73 74 75 |
# File 'lib/wordpress_deploy/storage/ftp.rb', line 73 def transmit raise NotImplementedError end |
#transmit! ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/wordpress_deploy/storage/ftp.rb', line 79 def transmit! connect files = Dir.glob(File.join(Config.wp_dir, "**/*")).sort files.each do |file| put_file file end ensure close end |
#user(new_user = nil) ⇒ Object
47 48 49 50 |
# File 'lib/wordpress_deploy/storage/ftp.rb', line 47 def user(new_user = nil) @user = new_user.to_s unless new_user.nil? @user end |