Class: RIO::FTP::FS
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#basename, #cleanpath, #dirname, #extname, #fnmatch?, #join
Constructor Details
#initialize(uri) ⇒ FS
Returns a new instance of FS.
34
35
36
37
38
|
# File 'lib/rio/ftp/fs.rb', line 34
def initialize(uri)
@uri = uri.clone
@file = ::File
@conn = nil
end
|
Instance Attribute Details
Returns the value of attribute uri.
33
34
35
|
# File 'lib/rio/ftp/fs.rb', line 33
def uri
@uri
end
|
Class Method Details
.create(*args) ⇒ Object
39
40
41
|
# File 'lib/rio/ftp/fs.rb', line 39
def self.create(*args)
new(*args)
end
|
Instance Method Details
#chdir(url, &block) ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/rio/ftp/fs.rb', line 86
def chdir(url,&block)
if block_given?
wd = conn.pwd
conn.chdir(remote_path(url))
begin
rtn = yield remote_wd
ensure
conn.chdir(wd)
end
return rtn
else
conn.chdir(remote_path(url))
end
end
|
48
49
50
|
# File 'lib/rio/ftp/fs.rb', line 48
def conn
@conn ||= ConnCache.instance.connect(@uri)
end
|
68
69
70
71
72
73
74
|
# File 'lib/rio/ftp/fs.rb', line 68
def cwd()
remote_wd = self.pwd.sub(%r{/*$},'/')
remote_rel = remote_wd.sub(/^#{self.remote_root}/,'')
wduri = uri.clone
wduri.path = remote_rel
wduri.to_s
end
|
#directory?(url) ⇒ Boolean
148
149
150
|
# File 'lib/rio/ftp/fs.rb', line 148
def directory?(url)
get_ftype(url) == :dir
end
|
51
52
53
|
# File 'lib/rio/ftp/fs.rb', line 51
def encoding
conn.encoding
end
|
#exist?(url) ⇒ Boolean
151
152
153
|
# File 'lib/rio/ftp/fs.rb', line 151
def exist?(url)
get_ftype(url) != :nada
end
|
#file?(url) ⇒ Boolean
145
146
147
|
# File 'lib/rio/ftp/fs.rb', line 145
def file?(url)
get_ftype(url) == :file
end
|
#get_ftype(url) ⇒ Object
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/rio/ftp/fs.rb', line 126
def get_ftype(url)
pth = remote_path(url)
ftype = nil
begin
conn.mdtm(pth)
ftype = :file
rescue Net::FTPPermError
wd = conn.pwd
begin
conn.chdir(pth)
ftype = :dir
rescue Net::FTPPermError
ftype = :nada
ensure
conn.chdir(wd)
end
end
ftype
end
|
65
66
67
|
# File 'lib/rio/ftp/fs.rb', line 65
def getwd()
self.pwd
end
|
#mkdir(url) ⇒ Object
100
101
102
103
|
# File 'lib/rio/ftp/fs.rb', line 100
def mkdir(url)
rp = remote_path(url)
conn.mkdir(rp)
end
|
#mkpath(url) ⇒ Object
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/rio/ftp/fs.rb', line 157
def mkpath(url)
pathparts = url.split('/')
pathparts.shift if pathparts[0] == ""
pathparts[0] = '/' + pathparts[0] if url.start_with?('/')
pth = ""
pathparts.each do |part|
pth += pth.empty? ? part : '/' + part
mkdir(pth) unless exist?(pth)
end
end
|
#mtime(url) ⇒ Object
113
114
115
|
# File 'lib/rio/ftp/fs.rb', line 113
def mtime(url)
conn.mtime(remote_path(url))
end
|
#mv(src_url, dst_url) ⇒ Object
104
105
106
|
# File 'lib/rio/ftp/fs.rb', line 104
def mv(src_url,dst_url)
conn.rename(remote_path(src_url),remote_path(dst_url))
end
|
#put(localfile, remote_file = ::File.basename(localfile)) ⇒ Object
122
123
124
|
# File 'lib/rio/ftp/fs.rb', line 122
def put(localfile,remote_file = ::File.basename(localfile))
conn.put(localfile,remote_path(remote_file))
end
|
64
|
# File 'lib/rio/ftp/fs.rb', line 64
def pwd() conn.pwd end
|
#remote_path(url) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/rio/ftp/fs.rb', line 75
def remote_path(url)
uri = Alt::URI.parse(url)
path = uri.path
wd = self.pwd
rpth = if path.start_with?('/')
path
else
self.remote_wd + path
end
rpth
end
|
#remote_root ⇒ Object
42
43
44
|
# File 'lib/rio/ftp/fs.rb', line 42
def remote_root
conn.remote_root.sub(%r{/*$},'/')
end
|
#remote_wd ⇒ Object
45
46
47
|
# File 'lib/rio/ftp/fs.rb', line 45
def remote_wd
conn.pwd.sub(%r{/*$},'/')
end
|
119
120
121
|
# File 'lib/rio/ftp/fs.rb', line 119
def rm(url)
conn.delete(remote_path(url))
end
|
#rmdir(url) ⇒ Object
116
117
118
|
# File 'lib/rio/ftp/fs.rb', line 116
def rmdir(url)
conn.rmdir(remote_path(url))
end
|
#rmtree(url) ⇒ Object
167
168
169
|
# File 'lib/rio/ftp/fs.rb', line 167
def rmtree(url)
_rment(url)
end
|
56
57
58
59
60
|
# File 'lib/rio/ftp/fs.rb', line 56
def root()
uri = @uri.clone
uri[:path] = '/'
uri.to_s
end
|
#size(url) ⇒ Object
107
108
109
|
# File 'lib/rio/ftp/fs.rb', line 107
def size(url)
conn.size(remote_path(url))
end
|
#symlink?(url) ⇒ Boolean
154
155
156
|
# File 'lib/rio/ftp/fs.rb', line 154
def symlink?(url)
false
end
|
#zero?(url) ⇒ Boolean
110
111
112
|
# File 'lib/rio/ftp/fs.rb', line 110
def zero?(url)
size(url) == 0
end
|