Dir.upload

git-svn-id: file:///home/svn/incoming/trunk@2422 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
Matt Miller 2005-04-18 05:42:46 +00:00
parent 5b83523155
commit 8d13da25af
2 changed files with 48 additions and 1 deletions

View File

@ -0,0 +1,16 @@
#!/usr/bin/ruby -I. -I../../lib
require 'DemoClient'
host = ARGV[0] || '127.0.0.1'
port = ARGV[1] || '12345'
src_dir = ARGV[2] || "/tmp/mirror_src_demo"
dst_dir = ARGV[3] || "c:\\personal\\temp\\dst_mirror"
client = DemoClient.new(host, port).client
begin
client.fs.dir.mkdir(dst_dir)
rescue
end
client.fs.dir.upload(dst_dir, src_dir, true)

View File

@ -132,7 +132,8 @@ class Dir < Rex::Post::Dir
#
##
# Mirrors the contents of a directory
# Downloads the contents of a remote directory a
# local directory, optionally in a recursive fashion.
def Dir.download(dst, src, recursive = false)
self.entries(src).each { |src_sub|
dst_item = dst + ::File::SEPARATOR + src_sub
@ -161,6 +162,36 @@ class Dir < Rex::Post::Dir
}
end
# Uploads the contents of a local directory to a remote
# directory, optionally in a recursive fashion.
def Dir.upload(dst, src, recursive = false)
::Dir.entries(src).each { |src_sub|
dst_item = dst + File::SEPARATOR + src_sub
src_item = src + ::File::SEPARATOR + src_sub
if (src_sub == '.' or src_sub == '..')
next
end
src_stat = ::File.stat(src_item)
if (src_stat.file?)
client.fs.file.upload(dst_item, src_item)
elsif (src_stat.directory?)
if (recursive == false)
next
end
begin
self.mkdir(dst_item)
rescue
end
upload(dst_item, src_item, recursive)
end
}
end
attr_reader :path
protected
attr_accessor :client