7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/ftputils/ftpconnection.rb', line 7
def self.connect(uri)
timeout(FTPUtils.timeout_period) do
if uri.match(/^ftp:\/\/(.*?):(.*?)@(.*?)(\/.*)*$/)
username = $1
password = $2
host = $3
connection = self.establish_connection(host, username, password)
begin
connection.chdir "/"
rescue Net::FTPTempError
connection = self.establish_connection(host, username, password, true)
retry
end
return connection
else
raise "Invalid FTP URL provided: #{uri}"
end
end
rescue Timeout::Error
raise "Connecting to #{uri} timed out after #{FTPUtils.timeout_period} seconds"
end
|