Created
September 1, 2011 13:10
-
-
Save spudtrooper/1186132 to your computer and use it in GitHub Desktop.
Download the photos (skipping sized and thumbnails) # in a phpAlbum photo gallery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# A ghetto way to download the photos (skipping sized and thumbnails) | |
# in a phpAlbum photo gallery. Create a file called credentials.rb | |
# that looks like this: | |
# | |
# HOSTNAME = 'example.com' | |
# USERNAME = 'example_user' | |
# PASSWORD = 'example-password' | |
# FOLDER = '/public_html/folder' | |
# | |
# Photos will be downloaded to 'photos' unless you provide another | |
# output folder. | |
# | |
require 'net/ftp' | |
require 'credentials' | |
def main(argv) | |
outdir = argv.shift || 'photos' | |
Dir.mkdir outdir if not File.exist? outdir | |
host = HOSTNAME | |
user = USERNAME | |
pass = PASSWORD | |
folder = FOLDER | |
Net::FTP.open host do |ftp| | |
ftp.login user,pass | |
ftp.chdir folder | |
dir = nil | |
remote_dir = nil | |
ftp.list '*' do |n| | |
n.scan /([^\:]+)\:$/ do | |
remote_dir = n.gsub /:/,'' | |
dir = File.join outdir,remote_dir | |
Dir.mkdir dir if not File.exist? dir | |
end | |
n.scan /\s+(\w+\.jpg)$/ do | |
f = $1 | |
remote_file = File.join remote_dir,f | |
localfile = File.join dir,f | |
localfile_tmp = localfile + ".tmp" | |
if not File.exist? localfile | |
puts "#{remote_file} --> #{localfile}" | |
begin | |
ftp.getbinaryfile remote_file,localfile_tmp | |
File.rename localfile_tmp,localfile | |
rescue Exception => e | |
STDERR.puts e | |
end | |
else | |
puts "Skipping #{remote_file}" | |
end | |
end | |
end | |
end | |
end | |
main ARGV |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment