I’m trying to recurse a directory and chmod the files on a remote ftp site.
What happens in the code works for the root directory then when it hits a
child directory and calls the chmod function recursively it hangs on the
next access of the ‘conn’ object. I cannot figure it out. Here’s the code:
···
require ‘net/ftp’
def print_info(msg)
puts Time.now.to_s + " :: #{msg}"
end
def chmod_files(conn, dir)
conn.chdir(dir)
pwd = conn.pwd()
conn.list() { |entry|
fileName = entry.split()[8]
print_info(“CHMOD #{PERMISSIONS} #{fileName}”)
conn.sendcmd(“SITE CHMOD #{PERMISSIONS} #{fileName}”)
if entry =~ /^d/ # It’s a directory
chmod_files(conn, fileName)
conn.chdir("…")
end
}
end
Main
HOST = ARGV[0] || "localhost"
PERMISSIONS = ARGV[1] || "0775"
STARTDIR = ARGV[2] || “.”
print_info(“Host = #{HOST}”)
print_info(“Permissions = #{PERMISSIONS}”)
print_info(“Start Dir = #{STARTDIR}”)
Net::FTP.open(HOST) { |conn|
conn.login(“blahID”, “blahPass”)
chmod_files(conn, STARTDIR)
}
Any help would be appreciated. I’ve wasted a lot of time on this…Please
tell me the standard libraries are getting better?