Skip to content

Instantly share code, notes, and snippets.

@kmiscia
Created April 27, 2012 15:45
Show Gist options
  • Save kmiscia/2510279 to your computer and use it in GitHub Desktop.
Save kmiscia/2510279 to your computer and use it in GitHub Desktop.
def cp(filename_with_path, destination_directory)
clean_filename_with_path = clean_dir(filename_with_path)
clean_destination = clean_dir(destination_directory)
local_filename = File.basename(filename_with_path)
local_destination = "/tmp/#{local_filename}"
if filename_with_path.local? && destination_directory.remote?
cmd = "#{curl_command} ftp://#{@host}/#{@destination_dir}/#{clean_destination}/#{local_filename} -T '#{local_destination}'"
execute_cmd(cmd)
elsif filename_with_path.local? && destination_directory.local?
FileUtils.cp(filename, destination_directory)
elsif filename_with_path.remote? && destination_directory.local?
cmd = "#{curl_command} ftp://#{@host}/#{@destination_dir}/#{clean_filename_with_path} -o '#{local_destination}'"
execute_cmd(cmd)
else # both remote
cmd = "#{curl_command} ftp://#{@host}/#{@destination_dir}/#{clean_filename_with_path} -o '#{local_destination}'"
execute_cmd(cmd)
cmd = "#{curl_command} ftp://#{@host}/#{@destination_dir}/#{clean_destination}/#{local_filename} -T '#{local_destination}'"
execute_cmd(cmd)
FileUtils.rm(local_destination) # TODO make sure this returns the value we want
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment