#!/usr/bin/env ruby require 'uri' require 'rubygems' require 'net/dav' dav_user = ENV['DAVUSER'] dav_pass = ENV['DAVPASS'] cmd = $*[0] case cmd when 'put' url = URI.parse $*[2] file = $*[1] when 'get' url = URI.parse $*[1] file = $*[2] else url = URI.parse $*[1] end res = Net::DAV.start(url) { |dav| dav.credentials(dav_user, dav_pass) if dav_user case cmd when 'put' File.open(file, "r") do |stream| dav.put(url.path, stream, File.size(file)) end when 'get' if file.nil? dav.get(url.path) do |str| $stdout.print str end else File.open(file, "w") do |stream| dav.get(url.path) do |str| stream.print str end end end when 'lsr' dav.find(url.path, :recursive => true) do |item| puts "#{item[:size]}\t#{item[:uri]}" end when 'ls' dav.find(url.path) do |item| puts "#{item[:size]}\t#{item[:uri]}" end when 'mkdir' dav.mkdir(url.path) else puts "unknown command" end }