-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.rb
48 lines (40 loc) · 1.17 KB
/
deploy.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require 'net/ftp'
# http://www.tylerclemons.com/ftp-fun-with-ruby/
def send_it(local, remote)
puts "sending " + local
#open local and remote directories
Dir.chdir(local)
@ftp.chdir(remote)
#make a local copy of file list to reduce network calls
remote_list = @ftp.nlst()
Dir.entries(".").each do |thefile|
#be sure not to try and send the current and parent directory
if thefile != "." and thefile != ".."
filename = File.basename(thefile)
#check if this is a file
if not File.directory?(thefile)
@ftp.putbinaryfile(thefile,thefile)
else
if not remote_list.index(filename)
@ftp.mkdir(filename)
end
#make recursive call
send_it(filename,filename)
#move back up to parent directory after sending directory
@ftp.chdir("..")
Dir.chdir("..")
end
end
end
end
username = ARGV[0]
password = ARGV[1]
local = "."
remote = "/public_html/"
@ftp = Net::FTP.new('ftp.davidssons.com')
@ftp.login(username, password)
#files = ftp.chdir('pub/lang/ruby/contrib')
#files = ftp.list('n*')
#ftp.getbinaryfile('nif.rb-0.91.gz', 'nif.gz', 1024)
send_it(local, remote)
@ftp.close