-
Notifications
You must be signed in to change notification settings - Fork 22
/
polar_ftp
executable file
·69 lines (58 loc) · 1.38 KB
/
polar_ftp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env ruby
# List content and download files through USB connection
require "optparse"
require "#{File.dirname(__FILE__)}/lib/polar_ftp"
def usage
puts "Usage:"
puts " #{__FILE__} [options] DIR <directory>"
puts " #{__FILE__} [options] GET <file> [<output_file>]"
puts " #{__FILE__} [options] SYNC [<output_dir>]"
puts
puts "Options:"
puts " -d, --dev=DEVICE Serial port device (for Polar Ignite, Vantage...)"
puts " -h Help"
end
options = {}
OptionParser.new do |opts|
opts.on("-dDEVICE", "--dev=DEVICE", "Serial port device (for Polar Ignite, Vantage...)") do |d|
options[:device] = d
end
opts.on("-h", "--help", "Usage") do
usage
exit
end
end.parse!
polar_ftp = PolarFtp.new(options)
case (ARGV[0] || '').upcase
when 'DIR'
# Directory listing
remote_dir = ARGV[1]
unless remote_dir
usage
exit -2
end
if content = polar_ftp.dir(remote_dir)
content.entries.each do |e|
if e.name[-1..-1] == '/'
# sub directory
puts " #{e.name}"
else
# file
puts " #{"%-16s" % e.name}#{"%10i" % e.size}"
end
end
end
when 'GET'
# File download
remote_file = ARGV[1]
unless remote_file
usage
exit -2
end
polar_ftp.get(remote_file, ARGV[2])
when 'SYNC'
polar_ftp.sync(ARGV[1])
else
usage
exit -2
end