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.
45
46
47
48
49
|
# File 'lib/rio/ftp/fs.rb', line 45
def initialize(uri)
@uri = uri.clone
@file = ::File
@conn = nil
end
|
Instance Attribute Details
Returns the value of attribute uri.
44
45
46
|
# File 'lib/rio/ftp/fs.rb', line 44
def uri
@uri
end
|
Class Method Details
.create(*args) ⇒ Object
50
51
52
|
# File 'lib/rio/ftp/fs.rb', line 50
def self.create(*args)
new(*args)
end
|
Instance Method Details
#chdir(url, &block) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/rio/ftp/fs.rb', line 84
def chdir(url,&block)
if block_given?
wd = conn.pwd
conn.chdir(remote_path(url))
begin
rtn = yield remote_path(url)
ensure
conn.chdir(wd)
end
return rtn
else
conn.chdir(remote_path(url))
end
end
|
56
57
58
|
# File 'lib/rio/ftp/fs.rb', line 56
def conn
@conn ||= ConnCache.instance.connect(@uri)
end
|
74
75
76
77
78
79
80
|
# File 'lib/rio/ftp/fs.rb', line 74
def cwd()
remote_wd = self.pwd
remote_rel = remote_wd.sub(/^#{self.remote_root}/,'')
wduri = uri.clone
wduri.path = remote_rel
wduri.to_s
end
|
#directory?(url) ⇒ Boolean
143
144
145
|
# File 'lib/rio/ftp/fs.rb', line 143
def directory?(url)
get_ftype(url) == 'dir'
end
|
#exist?(url) ⇒ Boolean
146
147
148
|
# File 'lib/rio/ftp/fs.rb', line 146
def exist?(url)
get_ftype(url) != 'nada'
end
|
#file?(url) ⇒ Boolean
140
141
142
|
# File 'lib/rio/ftp/fs.rb', line 140
def file?(url)
get_ftype(url) == 'file'
end
|
#get_ftype(url) ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/rio/ftp/fs.rb', line 120
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
|
71
72
73
|
# File 'lib/rio/ftp/fs.rb', line 71
def getwd()
self.pwd
end
|
#mkdir(url) ⇒ Object
98
99
100
|
# File 'lib/rio/ftp/fs.rb', line 98
def mkdir(url)
conn.mkdir(remote_path(url))
end
|
#mkpath(url) ⇒ Object
152
153
154
155
156
157
158
159
160
|
# File 'lib/rio/ftp/fs.rb', line 152
def mkpath(url)
tpath = rio(url)
tmprio = tpath.root
pathparts = tpath.path.split('/')[1..-1]
pathparts.each do |part|
tmprio.join!(part)
tmprio.mkdir
end
end
|
#mtime(url) ⇒ Object
110
111
112
|
# File 'lib/rio/ftp/fs.rb', line 110
def mtime(url)
conn.mtime(remote_path(url))
end
|
#mv(src_url, dst_url) ⇒ Object
101
102
103
|
# File 'lib/rio/ftp/fs.rb', line 101
def mv(src_url,dst_url)
conn.rename(remote_path(src_url),remote_path(dst_url))
end
|
70
|
# File 'lib/rio/ftp/fs.rb', line 70
def pwd() conn.pwd end
|
#remote_path(url) ⇒ Object
81
82
83
|
# File 'lib/rio/ftp/fs.rb', line 81
def remote_path(url)
self.remote_root+RIO::RL.url2fs(URI(url).path)
end
|
#remote_root ⇒ Object
53
54
55
|
# File 'lib/rio/ftp/fs.rb', line 53
def remote_root
conn.remote_root
end
|
116
117
118
|
# File 'lib/rio/ftp/fs.rb', line 116
def rm(url)
conn.delete(remote_path(url))
end
|
#rmdir(url) ⇒ Object
113
114
115
|
# File 'lib/rio/ftp/fs.rb', line 113
def rmdir(url)
conn.rmdir(remote_path(url))
end
|
#rmtree(url) ⇒ Object
161
162
163
164
|
# File 'lib/rio/ftp/fs.rb', line 161
def rmtree(url)
ario = rio(url)
_rment(ario)
end
|
62
63
64
65
66
|
# File 'lib/rio/ftp/fs.rb', line 62
def root()
uri = @uri.clone
uri.path = '/'
uri.to_s
end
|
#size(url) ⇒ Object
104
105
106
|
# File 'lib/rio/ftp/fs.rb', line 104
def size(url)
conn.size(remote_path(url))
end
|
#symlink?(url) ⇒ Boolean
149
150
151
|
# File 'lib/rio/ftp/fs.rb', line 149
def symlink?(url)
false
end
|
#zero?(url) ⇒ Boolean
107
108
109
|
# File 'lib/rio/ftp/fs.rb', line 107
def zero?(url)
size(url) == 0
end
|