forked from cmaion/polar
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpolar_ftp
More file actions
executable file
·85 lines (71 loc) · 1.5 KB
/
Copy pathpolar_ftp
File metadata and controls
executable file
·85 lines (71 loc) · 1.5 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env ruby
# List content and download files through USB connection
require "#{File.dirname(__FILE__)}/lib/polar_ftp"
def usage
puts "Usage:"
puts " #{__FILE__} DIR <directory>"
puts " #{__FILE__} GET <file> [<output_file>]"
puts " #{__FILE__} MKDIR <directory>"
puts " #{__FILE__} PUT <source_file> <remote_path>"
puts " #{__FILE__} DEL <file>"
puts " #{__FILE__} SYNC [<output_dir>]"
end
polar_ftp = PolarFtp.new
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])
when 'DEL'
# Entry remove
remote_path = ARGV[1]
unless remote_path
usage
exit -2
end
polar_ftp.del(remote_path)
when 'MKDIR'
# Directory create
remote_dir = ARGV[1]
unless remote_dir
usage
exit -2
end
polar_ftp.put(remote_dir)
when 'PUT'
# File put
source_file = ARGV[1]
remote_path = ARGV[2]
unless source_file && remote_path
usage
exit -2
end
polar_ftp.put_file(source_file, remote_path)
else
usage
exit -2
end