1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

*** empty log message ***

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@774 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shugo 2000-06-22 05:37:12 +00:00
parent fac7f59b31
commit 4b4cad81e7
2 changed files with 37 additions and 9 deletions

View file

@ -1,3 +1,7 @@
Thu Jun 22 13:49:02 2000 Uechi Yasumasa <uechi@ryucom.ne.jp>
* lib/net/ftp.rb: support resume.
Thu Jun 22 13:37:19 2000 WATANABE Hirofumi <eban@os.rim.or.jp> Thu Jun 22 13:37:19 2000 WATANABE Hirofumi <eban@os.rim.or.jp>
* eval.c (rb_thread_sleep_forever): merge pause() macro. * eval.c (rb_thread_sleep_forever): merge pause() macro.

View file

@ -26,7 +26,7 @@ module Net
FTP_PORT = 21 FTP_PORT = 21
CRLF = "\r\n" CRLF = "\r\n"
attr_accessor :passive, :return_code, :debug_mode attr_accessor :passive, :return_code, :debug_mode, :resume
attr_reader :welcome, :lastresp attr_reader :welcome, :lastresp
def FTP.open(host, user = nil, passwd = nil, acct = nil) def FTP.open(host, user = nil, passwd = nil, acct = nil)
@ -38,6 +38,7 @@ module Net
@passive = false @passive = false
@return_code = "\n" @return_code = "\n"
@debug_mode = false @debug_mode = false
@resume = false
if host if host
connect(host) connect(host)
if user if user
@ -188,16 +189,28 @@ module Net
end end
private :makepasv private :makepasv
def transfercmd(cmd) def transfercmd(cmd, rest_offset = nil)
if @passive if @passive
host, port = makepasv host, port = makepasv
conn = open_socket(host, port) conn = open_socket(host, port)
if @resume and rest_offset
resp = sendcmd("REST " + rest_offset.to_s)
if resp[0] != ?3
raise FTPReplyError, resp
end
end
resp = sendcmd(cmd) resp = sendcmd(cmd)
if resp[0] != ?1 if resp[0] != ?1
raise FTPReplyError, resp raise FTPReplyError, resp
end end
else else
sock = makeport sock = makeport
if @resume and rest_offset
resp = sendcmd("REST " + rest_offset.to_s)
if resp[0] != ?3
raise FTPReplyError, resp
end
end
resp = sendcmd(cmd) resp = sendcmd(cmd)
if resp[0] != ?1 if resp[0] != ?1
raise FTPReplyError, resp raise FTPReplyError, resp
@ -245,10 +258,10 @@ module Net
@welcome = resp @welcome = resp
end end
def retrbinary(cmd, blocksize, callback = Proc.new) def retrbinary(cmd, blocksize, rest_offset = nil, callback = Proc.new)
synchronize do synchronize do
voidcmd("TYPE I") voidcmd("TYPE I")
conn = transfercmd(cmd) conn = transfercmd(cmd, rest_offset)
loop do loop do
data = conn.read(blocksize) data = conn.read(blocksize)
break if data == nil break if data == nil
@ -283,14 +296,14 @@ module Net
end end
end end
def storbinary(cmd, file, blocksize, callback = nil) def storbinary(cmd, file, blocksize, rest_offset = nil, callback = nil)
if iterator? if iterator?
callback = Proc.new callback = Proc.new
end end
use_callback = callback.is_a?(Proc) use_callback = callback.is_a?(Proc)
synchronize do synchronize do
voidcmd("TYPE I") voidcmd("TYPE I")
conn = transfercmd(cmd) conn = transfercmd(cmd, rest_offset)
loop do loop do
buf = file.read(blocksize) buf = file.read(blocksize)
break if buf == nil break if buf == nil
@ -329,10 +342,16 @@ module Net
callback = Proc.new callback = Proc.new
end end
use_callback = callback.is_a?(Proc) use_callback = callback.is_a?(Proc)
f = open(localfile, "w") if @resume
rest_offset = File.size?(localfile)
f = open(localfile, "a")
else
rest_offset = nil
f = open(localfile, "w")
end
begin begin
f.binmode f.binmode
retrbinary("RETR " + remotefile, blocksize) do |data| retrbinary("RETR " + remotefile, blocksize, rest_offset) do |data|
f.write(data) f.write(data)
callback.call(data) if use_callback callback.call(data) if use_callback
end end
@ -363,10 +382,15 @@ module Net
callback = Proc.new callback = Proc.new
end end
use_callback = callback.is_a?(Proc) use_callback = callback.is_a?(Proc)
if @resume
rest_offset = size(remotefile)
else
rest_offset = nil
end
f = open(localfile) f = open(localfile)
begin begin
f.binmode f.binmode
storbinary("STOR " + remotefile, f, blocksize) do |data| storbinary("STOR " + remotefile, f, blocksize, rest_offset) do |data|
callback.call(data) if use_callback callback.call(data) if use_callback
end end
ensure ensure