summaryrefslogtreecommitdiff
path: root/lib/net
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-07-03 05:28:01 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-07-03 05:28:01 +0000
commit8e346d8cb19641c2246f52699552f0d8da3a9e0b (patch)
tree7dad42ebc83d3e5b91969b67a198e371f81f28d0 /lib/net
parent9620b20227a60b30ed405f7fd3299f7567fc61ad (diff)
* lib/net/ftp.rb (get): new method.
* lib/net/ftp.rb (putt): ditto. * lib/net/ftp.rb (binary): ditto. * lib/net/ftp.rb (binary=): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2621 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/net')
-rw-r--r--lib/net/ftp.rb31
1 files changed, 25 insertions, 6 deletions
diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb
index da380fcdb4..1d8cbba554 100644
--- a/lib/net/ftp.rb
+++ b/lib/net/ftp.rb
@@ -28,7 +28,7 @@ module Net
DEFAULT_BLOCKSIZE = 4096
- attr_accessor :passive, :return_code, :debug_mode, :resume
+ attr_accessor :binary, :passive, :return_code, :debug_mode, :resume
attr_reader :welcome, :lastresp
def FTP.open(host, user = nil, passwd = nil, acct = nil)
@@ -37,6 +37,7 @@ module Net
def initialize(host = nil, user = nil, passwd = nil, acct = nil)
super()
+ @binary = true
@passive = false
@return_code = "\n"
@debug_mode = false
@@ -48,7 +49,7 @@ module Net
end
end
end
-
+
def open_socket(host, port)
if defined? SOCKSsocket and ENV["SOCKS_SERVER"]
@passive = true
@@ -326,7 +327,7 @@ module Net
voidresp
end
end
-
+
def getbinaryfile(remotefile, localfile = File.basename(remotefile),
blocksize = DEFAULT_BLOCKSIZE, &block)
if @resume
@@ -359,8 +360,17 @@ module Net
f.close
end
end
+
+ def get(localfile, remotefile = File.basename(localfile),
+ blocksize = DEFAULT_BLOCKSIZE, &block)
+ unless @binary
+ gettextfile(localfile, remotefile, &block)
+ else
+ getbinaryfile(localfile, remotefile, blocksize, &block)
+ end
+ end
- def putbinaryfile(localfile, remotefile,
+ def putbinaryfile(localfile, remotefile = File.basename(localfile),
blocksize = DEFAULT_BLOCKSIZE, &block)
if @resume
rest_offset = size(remotefile)
@@ -376,7 +386,7 @@ module Net
end
end
- def puttextfile(localfile, remotefile, &block)
+ def puttextfile(localfile, remotefile = File.basename(localfile), &block)
f = open(localfile)
begin
storlines("STOR " + remotefile, f, &block)
@@ -384,7 +394,16 @@ module Net
f.close
end
end
-
+
+ def put(localfile, remotefile = File.basename(localfile),
+ blocksize = DEFAULT_BLOCKSIZE, &block)
+ unless @binary
+ puttextfile(localfile, remotefile, &block)
+ else
+ putbinaryfile(localfile, remotefile, blocksize, &block)
+ end
+ end
+
def acct(account)
cmd = "ACCT " + account
voidcmd(cmd)