Sha256: ecfd45889cd6c2ee87d21819682bd434086b42d3ec5a7e9c393e733ef0d8793d

Contents?: true

Size: 1.2 KB

Versions: 16

Compression:

Stored size: 1.2 KB

Contents

#!/usr/bin/ruby

# This example script is used for testing the writing to a file.
# It will attempt to connect to a specific share and then write to a specified file.
# Example usage: ruby write_file.rb 192.168.172.138 msfadmin msfadmin TEST_SHARE test.txt "data to write"
# This will try to connect to \\192.168.172.138\TEST_SHARE with the msfadmin:msfadmin credentials
# and write "data to write" the file test.txt

require 'bundler/setup'
require 'ruby_smb'

address  = ARGV[0]
username = ARGV[1]
password = ARGV[2]
share    = ARGV[3]
file     = ARGV[4]
data     = ARGV[5]
path     = "\\\\#{address}\\#{share}"

sock = TCPSocket.new address, 445
dispatcher = RubySMB::Dispatcher::Socket.new(sock)

client = RubySMB::Client.new(dispatcher, smb1: true, smb2: true, username: username, password: password)
protocol = client.negotiate
status = client.authenticate

puts "#{protocol} : #{status}"

begin
  tree = client.tree_connect(path)
  puts "Connected to #{path} successfully!"
rescue StandardError => e
  puts "Failed to connect to #{path}: #{e.message}"
end

file = tree.open_file(filename: file, write: true, disposition: RubySMB::Dispositions::FILE_OVERWRITE_IF)

result = file.write(data: data)
puts result.to_s
file.close

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ruby_smb-2.0.2 examples/write_file.rb
ruby_smb-2.0.1 examples/write_file.rb
ruby_smb-2.0.0 examples/write_file.rb
ruby_smb-1.1.0 examples/write_file.rb
ruby_smb-1.0.5 examples/write_file.rb
ruby_smb-1.0.4 examples/write_file.rb
ruby_smb-1.0.3 examples/write_file.rb
ruby_smb-1.0.2 examples/write_file.rb
ruby_smb-1.0.1 examples/write_file.rb
ruby_smb-1.0.0 examples/write_file.rb
ruby_smb-0.0.24 examples/write_file.rb
ruby_smb-0.0.23 examples/write_file.rb
ruby_smb-0.0.22 examples/write_file.rb
ruby_smb-0.0.21 examples/write_file.rb
ruby_smb-0.0.20 examples/write_file.rb
ruby_smb-0.0.19 examples/write_file.rb