diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-06-22 05:37:12 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-06-22 05:37:12 +0000 |
commit | 2c4dd0158164639963d6957bb20a5606a807c5a6 (patch) | |
tree | b420d626e8ae38578ecb08a8f48e4152c944e36f | |
parent | a0030333f4df5972660501a92686d736f0fa074a (diff) | |
download | ruby-2c4dd0158164639963d6957bb20a5606a807c5a6.tar.gz ruby-2c4dd0158164639963d6957bb20a5606a807c5a6.tar.xz ruby-2c4dd0158164639963d6957bb20a5606a807c5a6.zip |
*** empty log message ***
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@774 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | lib/net/ftp.rb | 42 |
2 files changed, 37 insertions, 9 deletions
@@ -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> * eval.c (rb_thread_sleep_forever): merge pause() macro. diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb index 11521d16c..3c2d97c3b 100644 --- a/lib/net/ftp.rb +++ b/lib/net/ftp.rb @@ -26,7 +26,7 @@ module Net FTP_PORT = 21 CRLF = "\r\n" - attr_accessor :passive, :return_code, :debug_mode + attr_accessor :passive, :return_code, :debug_mode, :resume attr_reader :welcome, :lastresp def FTP.open(host, user = nil, passwd = nil, acct = nil) @@ -38,6 +38,7 @@ module Net @passive = false @return_code = "\n" @debug_mode = false + @resume = false if host connect(host) if user @@ -188,16 +189,28 @@ module Net end private :makepasv - def transfercmd(cmd) + def transfercmd(cmd, rest_offset = nil) if @passive host, port = makepasv 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) if resp[0] != ?1 raise FTPReplyError, resp end else 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) if resp[0] != ?1 raise FTPReplyError, resp @@ -245,10 +258,10 @@ module Net @welcome = resp end - def retrbinary(cmd, blocksize, callback = Proc.new) + def retrbinary(cmd, blocksize, rest_offset = nil, callback = Proc.new) synchronize do voidcmd("TYPE I") - conn = transfercmd(cmd) + conn = transfercmd(cmd, rest_offset) loop do data = conn.read(blocksize) break if data == nil @@ -283,14 +296,14 @@ module Net end end - def storbinary(cmd, file, blocksize, callback = nil) + def storbinary(cmd, file, blocksize, rest_offset = nil, callback = nil) if iterator? callback = Proc.new end use_callback = callback.is_a?(Proc) synchronize do voidcmd("TYPE I") - conn = transfercmd(cmd) + conn = transfercmd(cmd, rest_offset) loop do buf = file.read(blocksize) break if buf == nil @@ -329,10 +342,16 @@ module Net callback = Proc.new end 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 f.binmode - retrbinary("RETR " + remotefile, blocksize) do |data| + retrbinary("RETR " + remotefile, blocksize, rest_offset) do |data| f.write(data) callback.call(data) if use_callback end @@ -363,10 +382,15 @@ module Net callback = Proc.new end use_callback = callback.is_a?(Proc) + if @resume + rest_offset = size(remotefile) + else + rest_offset = nil + end f = open(localfile) begin f.binmode - storbinary("STOR " + remotefile, f, blocksize) do |data| + storbinary("STOR " + remotefile, f, blocksize, rest_offset) do |data| callback.call(data) if use_callback end ensure |