summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--lib/net/ftp.rb54
2 files changed, 37 insertions, 26 deletions
diff --git a/ChangeLog b/ChangeLog
index 0f611d0c52..b548ca8ef8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Thu Jul 31 00:17:19 2003 Shugo Maeda <shugo@ruby-lang.org>
+
+ * lib/net/ftp.rb (return_code): obsolete.
+
+ * lib/net/ftp.rb (last_response_code): new method. lastresp is now
+ alias to last_response_code.
+
+ * lib/net/ftp.rb (last_response): new method.
+
Wed Jul 30 22:35:19 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* lib/mkmf.rb (dir_config): allow multiple directories separated
diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb
index d703f20733..585c14b004 100644
--- a/lib/net/ftp.rb
+++ b/lib/net/ftp.rb
@@ -67,9 +67,6 @@ module Net
# When +true+, the connection is in passive mode. Default: false.
attr_accessor :passive
- # The ASCII code used to separate lines.
- attr_accessor :return_code
-
# When +true+, all traffic to and from the server is written
# to +$stdout+. Default: +false+.
attr_accessor :debug_mode
@@ -81,8 +78,12 @@ module Net
# The server's welcome message.
attr_reader :welcome
+ # The server's last response code.
+ attr_reader :last_response_code
+ alias lastresp last_response_code
+
# The server's last response.
- attr_reader :lastresp
+ attr_reader :last_response
#
# A synonym for +FTP.new+, but with a mandatory host parameter.
@@ -112,7 +113,6 @@ module Net
super()
@binary = true
@passive = false
- @return_code = "\n"
@debug_mode = false
@resume = false
if host
@@ -123,6 +123,15 @@ module Net
end
end
+ def return_code
+ $stderr.puts("warning: Net::FTP#return_code is obsolete and do nothing")
+ return "\n"
+ end
+
+ def return_code=(s)
+ $stderr.puts("warning: Net::FTP#return_code= is obsolete and do nothing")
+ end
+
def open_socket(host, port)
if defined? SOCKSsocket and ENV["SOCKS_SERVER"]
@passive = true
@@ -181,12 +190,7 @@ module Net
def getline
line = @sock.readline # if get EOF, raise EOFError
- if line[-2, 2] == CRLF
- line = line[0 .. -3]
- elsif line[-1] == ?\r or
- line[-1] == ?\n
- line = line[0 .. -2]
- end
+ line.sub!(/(\r\n|\n|\r)\z/n, "")
if @debug_mode
print "get: ", sanitize(line), "\n"
end
@@ -209,18 +213,17 @@ module Net
private :getmultiline
def getresp
- resp = getmultiline
- @lastresp = resp[0, 3]
- c = resp[0]
- case c
- when ?1, ?2, ?3
- return resp
- when ?4
- raise FTPTempError, resp
- when ?5
- raise FTPPermError, resp
+ @last_response = getmultiline
+ @last_response_code = @last_response[0, 3]
+ case @last_response_code
+ when /\A[123]/
+ return @last_response
+ when /\A4/
+ raise FTPTempError, @last_response
+ when /\A5/
+ raise FTPPermError, @last_response
else
- raise FTPProtoError, resp
+ raise FTPProtoError, @last_response
end
end
private :getresp
@@ -234,7 +237,7 @@ module Net
private :voidresp
#
- # WRITEME or make private
+ # Sends a command and returns the response.
#
def sendcmd(cmd)
synchronize do
@@ -244,7 +247,7 @@ module Net
end
#
- # WRITEME or make private
+ # Sends a command and expect a response beginning with '2'.
#
def voidcmd(cmd)
synchronize do
@@ -494,8 +497,7 @@ module Net
f = open(localfile, "w")
begin
retrlines("RETR " + remotefile) do |line|
- line = line + @return_code
- f.write(line)
+ f.puts(line)
yield(line) if block
end
ensure