Project

General

Profile

Feature #15964 ยป rfc2389.patch

darkphnx (Dan Wentworth), 06/28/2019 10:35 AM

View differences:

lib/net/ftp.rb
voidcmd(cmd)
end
#
# Issues a FEAT command
#
# Returns an array of supported optional features
#
def features
resp = sendcmd("FEAT")
if !resp.start_with?("211")
raise FTPReplyError, resp
end
feats = []
resp.split("\n").each do |line|
next if !line.start_with?(' ') # skip status lines
feats << line.strip
end
return feats
end
#
# Issues an OPTS command
# - name Should be the name of the option to set
# - params is any optional parameters to supply with the option
#
# example: option('UTF8', 'ON') => 'OPTS UTF8 ON'
#
def option(name, params = nil)
cmd = "OPTS #{name}"
cmd += " #{params}" if params
voidcmd(cmd)
end
#
# Closes the connection. Further operations are impossible until you open
# a new connection with #connect.
test/net/ftp/test_ftp.rb
end
end
def test_features
commands = []
server = create_ftp_server { |sock|
sock.print("220 (test_ftp).\r\n")
commands.push(sock.gets)
sock.print("211-Features\r\n")
sock.print(" LANG EN*\r\n")
sock.print(" UTF8\r\n")
sock.print("211 End\r\n")
}
begin
begin
ftp = Net::FTP.new
ftp.connect(SERVER_ADDR, server.port)
assert_equal(['LANG EN*', 'UTF8'], ftp.features)
assert_equal("FEAT\r\n", commands.shift)
assert_equal(nil, commands.shift)
ensure
ftp.close if ftp
end
ensure
server.close
end
end
def test_features_not_implemented
commands = []
server = create_ftp_server { |sock|
sock.print("220 (test_ftp).\r\n")
commands.push(sock.gets)
sock.print("502 Not Implemented\r\n")
}
begin
begin
ftp = Net::FTP.new
ftp.connect(SERVER_ADDR, server.port)
assert_raise(Net::FTPPermError) do
ftp.features
end
assert_equal("FEAT\r\n", commands.shift)
assert_equal(nil, commands.shift)
ensure
ftp.close if ftp
end
ensure
server.close
end
end
def test_option
commands = []
server = create_ftp_server { |sock|
sock.print("220 (test_ftp)\r\n")
commands.push(sock.gets)
sock.print("200 OPTS UTF8 command successful\r\n")
}
begin
begin
ftp = Net::FTP.new
ftp.connect(SERVER_ADDR, server.port)
ftp.option("UTF8", "ON")
assert_equal("OPTS UTF8 ON\r\n", commands.shift)
assert_equal(nil, commands.shift)
ensure
ftp.close if ftp
end
ensure
server.close
end
end
def test_option_not_implemented
commands = []
server = create_ftp_server { |sock|
sock.print("220 (test_ftp)\r\n")
commands.push(sock.gets)
sock.print("502 Not implemented\r\n")
}
begin
begin
ftp = Net::FTP.new
ftp.connect(SERVER_ADDR, server.port)
assert_raise(Net::FTPPermError) do
ftp.option("UTF8", "ON")
end
assert_equal("OPTS UTF8 ON\r\n", commands.shift)
assert_equal(nil, commands.shift)
ensure
ftp.close if ftp
end
ensure
server.close
end
end
def test_mlst
commands = []
server = create_ftp_server { |sock|
    (1-1/1)