Having a problem with following code. It will drop to the first directory
and then hang. Any help will be appreciated.
---- snip ----
require ‘net/ftp’
public
def chmodDir(ftp, dir)
ftp.chdir(dir)
puts ftp.pwd
ftp.list() do |e|
dir = e.split(/ +/)[8]
if e=~ /^d/
ftp.chmodDir(ftp, dir)
end
end
end
(site, user, pass, dir) = ARGV
ftp = Net::FTP.new(site, user, pass)
chmodDir(ftp, dir)
ftp.close()
---- snip ----
Thanks!
Greg B.
Greg Brondo wrote:
Having a problem with following code. It will drop to the first directory
and then hang. Any help will be appreciated.
---- snip ----
require ‘net/ftp’
public
def chmodDir(ftp, dir)
ftp.chdir(dir)
puts ftp.pwd
ftp.list() do |e|
dir = e.split(/ +/)[8]
if e=~ /^d/
ftp.chmodDir(ftp, dir) # <-------------
end
end
end
Maybe I’ve misread the code, but shouldn’t the marked line just be “chmodDir(ftp, dir)”?
H.
That should be just chmodDir(ftp, dir), no “ftp.”. “ftp.chmodDir” tries
to call the method chmodDir() on the Net::FTP object, which doesn’t
exist.
You could change your code to define it as a method of class Net::FTP
if tha’ts what you want, in which case it would be ftp.chmodDir(dir),
but otherwise just lose the “ftp.” so you call your own function
recursively.
-Mark
···
On Mon, Jan 19, 2004 at 11:24:11PM +0000, Greg Brondo wrote:
def chmodDir(ftp, dir)
ftp.chdir(dir)
puts ftp.pwd
ftp.list() do |e|
dir = e.split(/ +/)[8]
if e=~ /^d/
ftp.chmodDir(ftp, dir)
Harry Ohlsen wrote:
Maybe I’ve misread the code, but shouldn’t the marked line just be
“chmodDir(ftp, dir)”?
Presumably, there should also be some kind of chmod() call in there, too. Ie, something like …
def chmodDir(ftp, dir)
ftp.chdir(dir)
puts ftp.pwd
ftp.list() do |e|
dir = e.split(/ +/)[8]
if e=~ /^d/
ftp.chmod(dir) # <---------------- Change the subdirectory’s mode
chmodDir(ftp, dir)# <---------------- Recurse to handle its subdirectories
end
end
end
But, maybe you’re just trying to get the recursion working before adding that code. What’s more, I don’t even know whether there is a Net::FTP.chmod() method :-). I’m just guessing here.
H.