Return to Snippet

Revision: 3796
at September 13, 2007 18:17 by lmcdougall


Initial Code
equire 'net/http'
require 'rubygems'
require_gem 'flickr'
require_gem 'net-sftp'

flickr_username = "[email protected]"
flickr_pass = 'x'
strongie_pass = 'x'
strongie_username = 'johan'
strongie_upload_dir = "flickr_test"

flickr = Flickr.new 
flickr.login(flickr_username, flickr_pass)
user = flickr.users(flickr_username)

Net::SFTP.start("#{strongie_username}.strongspace.com", strongie_username, strongie_pass) do |sftp|
  Net::HTTP.start('static.flickr.com') do |http|
    user.photos.each do |photo|
      src_url = photo.source('Large').sub("http://static.flickr.com", '')    
      puts "Fetching \"#{photo.title}\"..."
      res = http.get(src_url)
      filename = File.basename(src_url)
      sftp.open_handle("/home/#{strongie_username}/#{strongie_upload_dir}/#{filename}", 'w') do |handle|
        result = sftp.write(handle, res.body)
        puts "Wrote #{filename} with result code: #{result.code}..."
      end    
    end
  end
end

Initial URL

                                

Initial Description

                                

Initial Title
Upload your Flickr photos to Strongspace

Initial Tags
http, ruby

Initial Language
Ruby