Created
April 22, 2014 20:48
-
-
Save McPolemic/11193752 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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