Skip to content

Added recursive directories creating (mkdir -p) on remote ftp server #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion lib/astrails/safe/ftp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ def save
Net::FTP.open(host) do |ftp|
ftp.connect(host, port)
ftp.login(user, password)

dir = File.dirname(full_path)
parts = dir.split("/")
growing_path = ""
for part in parts
next if part == ""
if growing_path == ""
growing_path = part
else
growing_path = File.join(growing_path, part)
end
puts "Trying to create remote directory (#{growing_path})" if verbose?
begin
ftp.mkdir(growing_path)
rescue Net::FTPPermError
puts "Remote directory (#{growing_path}) exists, or no enough permissions" if verbose?
end
end

puts "Sending #{@backup.path} to #{full_path}" if verbose?
begin
ftp.put(@backup.path, full_path)
Expand Down Expand Up @@ -82,4 +101,4 @@ def port

end
end
end
end