lib/pione/location/ftp-location.rb in pione-0.1.4 vs lib/pione/location/ftp-location.rb in pione-0.2.0

- old
+ new

@@ -1,11 +1,20 @@ module Pione module Location # FTPLocation represents locations on FTP server. class FTPLocation < BasicLocation set_scheme "ftp" + set_real_appendable false + # for myftp scheme + SCHEMES["myftp"] = self + + def initialize(uri) + uri = uri.to_ftp_scheme if uri.scheme == "myftp" + super(uri) + end + def rebuild(path) scheme = @uri.scheme auth = "%s:%s@" % [@uri.user, @uri.password] if @uri.user and @uri.password host = @uri.host port = ":%i" % @uri.port @@ -17,19 +26,23 @@ if exist? raise ExistAlready.new(self) else connect do |ftp| makedirs(ftp, @path.dirname) - file = Temppath.create - file.open("w") {|f| f.write(data)} - ftp.put(file.to_s, @path.to_s) + path = Temppath.create + Location[path].create(data) + ftp.put(path, @path.to_s) end end end def append(data) - exist? ? update(read + data) : create(data) + if exist? + update(read + data) + else + create(data) + end end def read begin data = nil @@ -68,11 +81,11 @@ def entries connect do |ftp| ftp.nlst(@path.to_s).map do |entry| rebuild(@path + entry) - end.select {|entry| entry.file?} + end end end def exist? file? or directory? @@ -105,10 +118,10 @@ orig.copy(self) end def move(dest) if dest.scheme == scheme and dest.host == host - ftp.rename(@path.to_s, dest.path.to_s) + connect{|ftp| ftp.rename(@path.to_s, dest.path.to_s)} else copy(dest) delete end end