Sha256: 5e986f9fe75df596932f4324c23f34124b5287662f7c5edeff8c85fe4cd6f821
Contents?: true
Size: 1.66 KB
Versions: 2
Compression:
Stored size: 1.66 KB
Contents
#!/usr/bin/env ruby require 'uri' require 'rubygems' require 'net/dav' dav_user = ENV['DAVUSER'] dav_pass = ENV['DAVPASS'] cmd = $*[0] def print_usage puts "usage: #{$0} COMMAND [ARGS]" puts "" puts "Available commands:" puts " ls List file or directory at URL" puts " lsr List file or directory recursively at URL" puts " get Get file from URL to stdout or to FILE" puts " put Put file from FILE to URL" puts " mkdir Create directory at URL" puts " gsub Replace content at URL from REGEXP to VALUE" exit end if $*.size < 2 print_usage end case cmd when 'put' url = URI.parse $*[2] file = $*[1] when 'get' url = URI.parse $*[1] file = $*[2] else url = URI.parse $*[1] end enable_curl = !ENV['DISABLE_CURL'] res = Net::DAV.start(url, :curl => enable_curl ) { |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) when 'gsub' re = Regexp.compile($*[2]) val = $*[3] dav.find(url.path) do |item| if (item.type == :file) item.content = item.content.gsub(re, val) end end else print_usage end }
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
net_dav-0.2.1 | bin/dav |
net_dav-0.2.0 | bin/dav |