In Files
Information
Class Index
          ![show/hide quicksearch [+]](../assets/icon/find.png)
        
        
        - Ratch
 - Ratch::Batch
 - Ratch::CLI
 - Ratch::ConfigUtils
 - Ratch::Console
 - Ratch::EmailUtils
 - Ratch::Emailer
 - Ratch::FTPUtils
 - Ratch::FileList
 - Ratch::FileNotFound
 - Ratch::Help
 - Ratch::POMUtils
 - Ratch::RDocUtils
 - Ratch::Script
 - Ratch::Shell
 - Ratch::System
 - Ratch::TarUtils
 - Ratch::XDGUtils
 - Ratch::ZlibUtils
 - FileTest
 - Hash
 - NilClass
 - Object
 - String
 
FTPUtils
FIXME: This module needs major work. Methods ftp_files and ftp_stage_transfer need to either be generalized and moved to Shell or Script, or removed.
Public Class Methods
Public Instance Methods
        
          ftp(keys)
          click to toggle source
        
        
        Use ftp to upload files.
    # File lib/ratch/utils/ftp.rb, line 20
20:     def ftp(keys)
21:       keys = upload_parameters(keys)
22: 
23:       # set transfer rules
24:       if keys.stage
25:         trans = ftp_stage_transfer(keys.stage)
26:       else
27:         ftp_files(keys.dir, keys.copy).each do |from|
28:           trans << [from,from]
29:         end
30:       end
31: 
32:       # append location of publication dir to from
33:       dir = keys.dir
34:       trans.collect!{ |from,to| [File.join(dir,from), to] }
35: 
36:       if keys.dryrun
37:         puts "ftp open #{keys.user}@#{keys.host}:#{keys.root}/"
38:         keys.trans.each do |f, t|
39:           puts "ftp put #{f} #{t}"
40:         end
41:       else
42:         Net::FTP.open(keys.host) do |ftp|
43:           ftp.login(keys.user) #password?
44:           ftp.chdir(keys.root)
45:           keys.trans.each do |f, t|
46:             puts "ftp #{f} #{t}" unless keys.quiet
47:             ftp.putbinaryfile( f, t, 1024 )
48:           end
49:         end
50:       end
51:     end
          
        
          ftp_files( dir, copy )
          click to toggle source
        
        
        Put together the list of files to copy.
     # File lib/ratch/utils/ftp.rb, line 89
 89:     def ftp_files( dir, copy )
 90:       Dir.chdir(dir) do
 91:         del, add = copy.partition{ |f| /^[-]/ =~ f }
 92: 
 93:         # remove - and + prefixes
 94:         del.collect!{ |f| f.sub(/^[-]/,'') }
 95:         add.collect!{ |f| f.sub(/^[+]/,'') }
 96: 
 97:         #del.concat(must_exclude)
 98: 
 99:         ftp_files = []
100:         add.each{ |g| files += Dir.glob(g) }
101:         del.each{ |g| files -= Dir.glob(g) }
102: 
103:         files.collect!{ |f| f.sub(/^\//,'') }
104: 
105:         return files
106:       end
107:     end
          
        
          ftp_stage_transfer( list )
          click to toggle source
        
        
        Combine three part stage list into a two part from->to list.
Using the stage list of three space separated fields.
fromdir file todir
This is used to generate a from -> to list of the form:
fromdir/file todir/file
     # File lib/ratch/utils/ftp.rb, line 119
119:     def ftp_stage_transfer( list )
120:       trans = []
121:       list.each do |line|
122:         trans << Shellwords.shellwords(line)
123:       end
124: 
125:       trans.collect! do |from, base, to|
126:         file = File.join(from,base)
127:         to = File.join(to,base)
128:         [from, to]
129:       end
130:     end
          
        
          sftp( keys )
          click to toggle source
        
        
        Use sftp to upload files.
    # File lib/ratch/utils/ftp.rb, line 55
55:     def sftp( keys )
56:       keys = upload_parameters(keys)
57: 
58:       # set transfer rules
59:       if keys.stage
60:         trans = ftp_stage_transfer(keys.stage)
61:       else
62:         ftp_files(keys.dir, keys.copy).each do |from|
63:           trans << [from,from]
64:         end
65:       end
66: 
67:       # append location of publication dir to from
68:       dir = keys.dir
69:       trans.collect!{ |from,to| [File.join(dir,from), to] }
70: 
71:       if keys.dryrun
72:         puts "sftp open #{keys.user}@#{keys.host}:#{keys.root}/"
73:         keys.trans.each do |f,t|
74:           puts "sftp put #{f} #{t}"
75:         end
76:       else
77:         Net::SFTP.start(keys.host, keys.user, keys.pass) do |sftp|
78:           #sftp.login( user )
79:           sftp.chdir(keys.root)
80:           keys.trans.each do |f,t|
81:             puts "sftp #{f} #{t}" unless keys.quiet
82:             sftp.put_file(f,t) #, 1024 )
83:           end
84:         end
85:       end
86:     end
          Disabled; run with --debug to generate this.