From 5d3c7f3b4aae406cc41284fc9a90d2fe813c7b9f Mon Sep 17 00:00:00 2001 From: William Vu Date: Wed, 25 Feb 2015 17:09:44 -0600 Subject: [PATCH] Add fsquery method --- lib/rex/proto/pjl/client.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/rex/proto/pjl/client.rb b/lib/rex/proto/pjl/client.rb index 6ba3426e7a..142c2a2bf4 100644 --- a/lib/rex/proto/pjl/client.rb +++ b/lib/rex/proto/pjl/client.rb @@ -117,6 +117,26 @@ class Client @sock.put(%Q{#{FSINIT} VOLUME = "#{volume}"\n}) end + # Query a file + # + # @param path [String] Remote path + # @return [Boolean] True if file exists + def fsquery(path) + if path !~ /^[0-2]:/ + raise ArgumentError, "Path must begin with 0:, 1:, or 2:" + end + + file = false + + @sock.put(%Q{#{FSQUERY} NAME = "#{path}"\n}) + + if @sock.get(DEFAULT_TIMEOUT) =~ /TYPE=(FILE|DIR)/m + file = true + end + + file + end + # List a directory # # @param path [String] Remote path