Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for path stat in ftp #1478

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/net/ftp.rb
Expand Up @@ -1107,10 +1107,13 @@ def abort

#
# Returns the status (STAT command).
# pathname - when stat is invoked with pathname as a parameter it acts like
# list but alot faster and over the same tcp session.
#
def status
line = "STAT" + CRLF
print "put: STAT\n" if @debug_mode
def status(pathname=nil)
line = pathname ? "STAT #{pathname}" : "STAT"
line = line + CRLF
print "put: #{line.chomp}\n" if @debug_mode
@sock.send(line, Socket::MSG_OOB)
return getresp
end
Expand Down
33 changes: 33 additions & 0 deletions test/net/ftp/test_ftp.rb
Expand Up @@ -1246,6 +1246,39 @@ def test_status
end
end

def test_status_path
commands = []
server = create_ftp_server { |sock|
sock.print("220 (test_ftp).\r\n")
commands.push(sock.gets)
sock.print("331 Please specify the password.\r\n")
commands.push(sock.gets)
sock.print("230 Login successful.\r\n")
commands.push(sock.gets)
sock.print("200 Switching to Binary mode.\r\n")
commands.push(sock.gets)
sock.print("213 End of status\r\n")
}
begin
begin
ftp = Net::FTP.new
ftp.read_timeout = 0.2
ftp.connect(SERVER_ADDR, server.port)
ftp.login
assert_match(/\AUSER /, commands.shift)
assert_match(/\APASS /, commands.shift)
assert_equal("TYPE I\r\n", commands.shift)
ftp.status "/"
assert_equal("STAT /\r\n", commands.shift)
assert_equal(nil, commands.shift)
ensure
ftp.close if ftp
end
ensure
server.close
end
end

def test_pathnames
require 'pathname'

Expand Down