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 | 4b4cad81e7d2bdc4750ea5043ce44bf37adb3997 (patch) | |
tree | b420d626e8ae38578ecb08a8f48e4152c944e36f /lib | |
parent | fac7f59b31b8760dcbaf20b147d1ee81f2b26768 (diff) | |
download | ruby-4b4cad81e7d2bdc4750ea5043ce44bf37adb3997.tar.gz |
*** empty log message ***
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@774 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/net/ftp.rb | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb index 11521d16c4..3c2d97c3b3 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 |