summaryrefslogtreecommitdiff
path: root/worker/tests/ftp.rb
diff options
context:
space:
mode:
Diffstat (limited to 'worker/tests/ftp.rb')
-rw-r--r--worker/tests/ftp.rb51
1 files changed, 51 insertions, 0 deletions
diff --git a/worker/tests/ftp.rb b/worker/tests/ftp.rb
new file mode 100644
index 0000000..cd0e754
--- /dev/null
+++ b/worker/tests/ftp.rb
@@ -0,0 +1,51 @@
+require 'timeout'
+
+
+#
+# Run an FTP test.
+#
+#
+# Return value
+# TRUE: The host is up
+#
+# FALSE: The host is not up
+#
+def ftp_test ( params )
+
+ #
+ # Get the hostname & port to test against.
+ #
+ host = params['target_host']
+ port = params['test_port']
+
+ puts "FTP testing host #{host}:#{port}"
+
+
+ begin
+ timeout(3) do
+
+ begin
+ socket = TCPSocket.new( host, port )
+ socket.puts( "QUIT")
+
+ banner = socket.gets(nil)
+ banner = banner[0,20]
+
+ socket.close()
+
+ if ( banner =~ /^220/ )
+ puts "FTP alive: #{banner}"
+ return true
+ end
+ rescue
+ puts "FTP exception on host #{host}:#{port} - #{$!}"
+ return false
+ end
+ end
+ rescue Timeout::Error => e
+ puts "TIMEOUT: #{e}"
+ return false
+ end
+
+ return false
+end