Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
3 total  XML / RSS feed 

Webdav upload utility

Command line utility to upload files to a webdav server.

Requires net_digest_auth.rb (snippet)

NB: Does not handle MKCOL, so the directory where you place the file must already exist.

Usage

$ ruby upload.rb cert.yml source destination


where cert.yml is a file of the form

username: USERNAME
password: PASSWORD


source is the path to the file to upload

destination is the URL of a directory on a webdav server to upload to.

# upload.rb
# Command line webdav upload script. Based off of 
# http://theexciter.com/articles/bingo

require 'net_digest_auth'
require 'yaml'
require 'uri'

abort("Usage: #{$0}    ") unless ARGV.size==3

auth = YAML.load_file(ARGV[0])
username = auth['username']
password = auth['password']

src = ARGV[1]
dst = ARGV[2]

if File.exists?(src)
  url = URI.parse(dst)
  Net::HTTP.start(url.host) do |http|
    res = http.put(url.request_uri, 'hello') # try putting something so
                                             # the server will return a
                                             # www-authenticate header
    req = Net::HTTP::Put.new("#{url.path}#{File.basename(src)}")
    req.digest_auth(username, password, res)
    response = http.request(req, File.open(src).read)
    puts response.code + " " + response.message
  end
else
  puts "No such file #{src.inspect}"
end

stop creating useless .ds_store files on your non-mac network share

http://docs.info.apple.com/article.html?artnum=301711

1. Open the Terminal.
2. Type:
defaults write com.apple.desktopservices DSDontWriteNetworkStores true

3. Press Return.
4. Restart the computer.

now you'll no longer fill the windows file server with annoying .ds_store files. you'll no longer unknowingly commit hundreds of irrelevent .ds_store files to your subversion repository mounted over webdav with auto-versioning. rejoice.

A simple WebDAV repository with user directories

The following snippet goes into the main Apache config (or a VirtualHost config). It allows you to create a simple repository access by WebDAV, with distinct logins for your users. All users must authenticate to access the /webstore directory, they can browse and see all subdirectories, but they can only upload into their own /webstore/user directory, or into any directory which may be created under /webstore, but not mentioned in the config.

You still need to have the mod_dav module installed and loaded, and to actually add all users into the dav.digest.passwd file using the htdigest command:

htdigest dav.digest.htpasswd foobar.com foo


The +Indexes option also makes it to possible to browse the repository using a regular web browser (with no upload rights, of course).

<Location /webstore>
  DAV On
  Options +Indexes
  AuthType Digest
  AuthName foobar.com
  AuthDigestFile /home/foobar/etc/dav.digest.passwd
  Require valid-user
  ForceType text/plain
Location>
/webstore/foo">
  Require valid-user
  
    Require user foo
  

"/webstore/bar">
  Require valid-user
  
    Require user bar
  

« Newer Snippets
Older Snippets »
3 total  XML / RSS feed