Class: SixCore::Ftp
- Inherits:
-
Object
- Object
- SixCore::Ftp
- Defined in:
- lib/sixcore/ftp.rb
Overview
Core FTP Class
Constant Summary collapse
Instance Attribute Summary collapse
-
#ftp ⇒ Object
readonly
Returns the value of attribute ftp.
Instance Method Summary collapse
-
#get(filename = '', localpath = '', remotepath = '') ⇒ Object
- Gets file from FTP filename
- String, Filename localpath
- String, Localpath remotepath
-
String, Remotepath.
-
#initialize(host, user = '', pass = '') ⇒ Ftp
constructor
- host
- String, Hostname user
- String, Username pass
-
String, Password.
-
#put(filename = '', localpath = '', remotepath = '', temp = false, staytemp = false) ⇒ Object
- Puts file on FTP filename
- String, Filename localpath
- String, Localpath remotepath
- String, Remotepath temp
- Boolean, When true, Uploads file as #filename_tmp staytemp
-
Boolean, When true, Uploaded file will remain as _tmp even after finishing.
-
#rename(filename = '', newfn = '', remotepath = '') ⇒ Object
- Renames file on FTP filename
- String, Filename newfn
- String, New Filename remotepath
-
String, Remotepath.
Constructor Details
#initialize(host, user = '', pass = '') ⇒ Ftp
- host
-
String, Hostname
- user
-
String, Username
- pass
-
String, Password
16 17 18 19 20 21 22 23 24 |
# File 'lib/sixcore/ftp.rb', line 16 def initialize(host, user = '', pass = '') @@log.debug SixCore::prep_msg 'Initialize', :component => COMPONENT @@log.debug "Creating connection to ftp://#{user}:#{pass}@#{host} ..." @host = host @user = user @pass = pass @ftp = Net::FTP.new(@host) @ftp.login(user=@user, passwd=@pass) end |
Instance Attribute Details
#ftp ⇒ Object (readonly)
Returns the value of attribute ftp.
8 9 10 |
# File 'lib/sixcore/ftp.rb', line 8 def ftp @ftp end |
Instance Method Details
#get(filename = '', localpath = '', remotepath = '') ⇒ Object
Gets file from FTP
- filename
-
String, Filename
- localpath
-
String, Localpath
- remotepath
-
String, Remotepath
30 31 32 33 |
# File 'lib/sixcore/ftp.rb', line 30 def get(filename = '', localpath = '', remotepath = '') @@log.debug "Downloading #{filename} from #{@host}#{remotepath} ..." @ftp.getbinaryfile("#{remotepath}#{filename}", "#{localpath}#{filename}", 1024) unless filename == '' end |
#put(filename = '', localpath = '', remotepath = '', temp = false, staytemp = false) ⇒ Object
Puts file on FTP
- filename
-
String, Filename
- localpath
-
String, Localpath
- remotepath
-
String, Remotepath
- temp
-
Boolean, When true, Uploads file as #filename_tmp
- staytemp
-
Boolean, When true, Uploaded file will remain as _tmp even after finishing
49 50 51 52 53 54 55 |
# File 'lib/sixcore/ftp.rb', line 49 def put(filename = '', localpath = '', remotepath = '', temp = false, staytemp = false) file = filename file = "#{file}_tmp" if temp @@log.debug "Uploading #{filename} to #{@host}#{remotepath} ..." @ftp.putbinaryfile("#{localpath}#{filename}", "#{remotepath}#{file}", 1024) unless filename == '' @ftp.rename("#{remotepath}#{file}", "#{remotepath}#{filename}") if temp && !staytemp end |
#rename(filename = '', newfn = '', remotepath = '') ⇒ Object
Renames file on FTP
- filename
-
String, Filename
- newfn
-
String, New Filename
- remotepath
-
String, Remotepath
39 40 41 |
# File 'lib/sixcore/ftp.rb', line 39 def rename(filename = '', newfn = '', remotepath = '') @ftp.rename("#{remotepath}#{filename}", "#{remotepath}#{newfn}") end |