Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.
taki edited this page Jun 15, 2018 · 21 revisions

Net::DAV Ruby WebDAV client

Net::DAV is a Ruby WebDAV client library in the style of Net::HTTP.

The Net::DAV gem makes it easier to read and update properties on files and folders on WebDAV enabled web servers. It features an API for traversing a directory structure on the server without having to mount the remote server as a local file system, and methods for authentication, copy, move, delete and write.

Net::DAV uses Net::Http and Nokogiri for XML. Curb can be used for HTTP if available.

Traversing files on remote WebDAV server

It can be used for scripts to do ad-hoc operations on large static websites with webdav server extensions. This script updates links in files in the folder “https://webdav.server.com/news/” with .html or .xml file extensions from ‘www.wrong.com’ to ‘www.right.com’. Username and passord are read from the environment variables DAVUSER and DAVPASS.


require 'rubygems'
require 'net/dav'

dav = Net::DAV.new("https://webdav.server.com/news/", :curl => false)
dav.verify_server = false
dav.credentials(ENV['DAVUSER'],ENV['DAVPASS'])

dav.find('.',:recursive=>true,:suppress_errors=>true,:filename=>/\.html|\.xml$/) do | item |
  puts "Checking: " + item.url.to_s
  if( item.content =~ /www.wrong.com/ )
    item.content = item.content.gsub("www.wrong.com", "www.right.com")
    puts "Updated: " + item.url.to_s
  end
end

The :suppress_errors option, makes the find print out a warning instead of raising an exception if it should stumble upon an error like a directory that returns a “403 Forbidden” error. The :filename option can be either a regexp or a string.

Clone this wiki locally