Skip to content

Instantly share code, notes, and snippets.

@McPolemic
Created April 22, 2014 20:48
Show Gist options
  • Save McPolemic/11193748 to your computer and use it in GitHub Desktop.
Save McPolemic/11193748 to your computer and use it in GitHub Desktop.
class NautilusUploadService
def initialize options
required = [:username,
:password,
:hostname,
:share,
:domain]
@username = options.fetch(:username)
@password = options.fetch(:password)
@hostname = options.fetch(:hostname)
@share = options.fetch(:share)
@domain = options.fetch(:domain)
end
def upload(local_path, remote_directory)
raise Errno::ENOENT unless File.exists? local_path
if File.directory? local_path
upload_directory(local_path, remote_directory)
else
upload_file(local_path, remote_directory)
end
end
def run_smbclient command
`smbclient -W #{@domain} -U #{@username} '\\\\#{@hostname}\\#{@share}' -c \"#{command}\"`
end
def upload_file(local_file, remote_directory)
command = "cd \"#{remote_directory}\"; put \"#{local_file}\""
run_smbclient command
end
def upload_directory(local_dir, remote_directory)
glob = File.join(local_dir, '*.pdf')
command = "recurse; prompt; cd \"#{remote_directory}\"; mput \"#{glob}\""
run_smbclient command
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment