2014-09-13 21 views
1

我需要下載的文件結構(超過4GB)從FTPS服務器(超過TLS協議隱含的FTP)。不幸的是wget不支持FTPS,但捲曲does。但curl不支持遞歸。如何從遞歸獲取文件和命令行FTPS服務器?

我需要在Ubuntu一個命令行工具解決方案。

任何想法?

+0

對不起,我忘了寫,那我需要一個命令行工具。但看標題.-) – 2014-09-13 08:20:31

+0

'wget'和'curl'是程序員通常使用的**軟件工具,所以它屬於這裏。見http://stackoverflow.com/help/on-topic – 2014-09-13 08:31:02

+0

你可以寫一個簡單的腳本它調用捲曲。 – jfly 2014-09-13 12:53:33

回答

0

沒有找到解決辦法,所以我寫了一個簡單的Ruby腳本,它可以爲每個人的起點:

#!/usr/bin/env ruby 
# encoding: utf-8 

require 'optparse' 

FILENAME_MATCH_REGEXP=/^[d\-rwx]+ [0-9]+ \w+ \w+[ ]+\d+[ ]+[a-zA-Z]+[ ]+\d+[ ]+\d+[ ]+(.*)$/ 

options = {} 
opts = OptionParser.new do |opts| 
    opts.banner = "Usage: curl_ftp_get_recursive.rb [options] url directory" 

    opts.on("-v", "--[no-]verbose", "Run verbosely") do |o| 
    options[:verbose] = o 
    end 

    options[:curl_options] = '-sS' 
    opts.on("-c", "--curl-options OPTIONS", "Curl options") do |o| 
    options[:curl_options] += " #{o}" 
    end 

    options[:output_dir] = '.' 
    opts.on("-o", "--output DIR", "Output directory, default=current directory") do |o| 
    options[:output_dir] = o 
    end 
end 

begin 
    opts.parse! 
    raise "Invalid number of arguments" if ARGV.count != 2 
rescue Exception => e 
    p "#{$0}: #{e.message}" 
    p opts 
    exit 1 
end 

# Remove trailing '/' if any 
url = ARGV[0].sub /\/*$/, '' 
root_dir = ARGV[1].sub /\/*$/, '' 
options[:output_dir] = options[:output_dir].sub /\/*$/, '' 

def get_dir options, url, dir 
    p "Reading directory '#{dir}'..." if options[:verbose] 

    output = `/usr/bin/curl #{options[:curl_options]} "#{url}/#{dir}"/` 
    exit 1 if $? != 0 
    dir_list = output.split "\n" 
    dir_list.each do |line| 
    p "Processing line '#{line}'..." if options[:verbose] 
    file_name = "#{dir}/#{line.match(FILENAME_MATCH_REGEXP)[1]}" 
    local_dir = "#{options[:output_dir]}/#{dir}" 
    if line.match /^d/ 
     get_dir options, url, file_name 
    else 
     p "Getting file '#{file_name}'..." 
     `mkdir -p "#{local_dir}"` 
     exit 1 if $? != 0 
     `/usr/bin/curl -o "#{options[:output_dir]}/#{file_name}" #{options[:curl_options]} "#{url}/#{file_name}"` 
     exit 1 if $? != 0 
    end 
    end 
end 

get_dir options, url, root_dir 

的利用方法:

./curl_ftp_get_recursive.rb -v -c --insecure ftps://MyUSerName:[email protected]:MyPort '/Directory to copy'