Forum: Ruby Net::FTP : How to check whether chdir succeeded?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C667185722eaecf12461cb423dc8b410?d=identicon&s=25 Ronald Fischer (Guest)
on 2007-06-06 10:44
(Received via mailing list)
Does anyone know a reliable way to detect, whether Net::FTP#chdir was
successful? Even if the directory does not exist, no exception is
thrown.

Ronald
Aee77dba395ece0a04c688b05b07cd63?d=identicon&s=25 Daniel Berger (Guest)
on 2007-06-06 16:34
(Received via mailing list)
On Jun 6, 2:43 am, "Ronald Fischer" <ronald.fisc...@venyon.com> wrote:
> Does anyone know a reliable way to detect, whether Net::FTP#chdir was
> successful? Even if the directory does not exist, no exception is
> thrown.

That's odd. I tried running this snippet, connecting from a Windows XP
Pro box to a RHEL box:

ftp = FTP.new(host, user, passwd)
ftp.chdir('/totally/bogus')
ftp.close

It raised an exception for me:

C:/ruby/lib/ruby/1.8/net/ftp.rb:243:in `getresp': 550 Failed to change
directory. (Net::FTPPermError)
        from C:/ruby/lib/ruby/1.8/net/ftp.rb:251:in `voidresp'
        from C:/ruby/lib/ruby/1.8/net/ftp.rb:274:in `voidcmd'
        from C:/ruby/lib/ruby/1.8/monitor.rb:238:in `synchronize'
        from C:/ruby/lib/ruby/1.8/net/ftp.rb:272:in `voidcmd'
        from C:/ruby/lib/ruby/1.8/net/ftp.rb:677:in `chdir'
        from ftp_test.rb:5

Can you tell use more about the platform you're connecting to? Maybe
it's not sending back an expected (or any) response with chdir. You
can tinker with FTP#sendcmd as well to see how it behaves. Or, just
ftp manually, and try to chdir to a bogus directory and see what it
does.

Regards,

Dan
017e05d1a49ffa59ea03e149e7af720b?d=identicon&s=25 Chris Shea (chrisshea)
on 2007-06-06 17:55
(Received via mailing list)
On Jun 6, 2:43 am, "Ronald Fischer" <ronald.fisc...@venyon.com> wrote:
> Does anyone know a reliable way to detect, whether Net::FTP#chdir was
> successful? Even if the directory does not exist, no exception is
> thrown.
>
> Ronald
> --
> Ronald Fischer <ronald.fisc...@venyon.com>
> Phone: +49-89-452133-162

You should be able to check with Net::FTP#pwd.  You can check out the
docs for Net::FTP here:
http://www.ruby-doc.org/stdlib/libdoc/net/ftp/rdoc...

HTH,
Chris
C667185722eaecf12461cb423dc8b410?d=identicon&s=25 Ronald Fischer (Guest)
on 2007-06-12 10:56
(Received via mailing list)
>
> You should be able to check with Net::FTP#pwd.

I think this does not work when the directory chdir'ed to is
reached via a symlink, and I also don't see an easy way,
how to check it with pwd for the cases the directory is
given via a relative path. Note that a general solution
must deal with cases such as

   chdir "foo/bar"
   chdir "foo/.."  # pwd after chdir will be the same as before

Ronald
C667185722eaecf12461cb423dc8b410?d=identicon&s=25 Ronald Fischer (Guest)
on 2007-06-12 11:13
(Received via mailing list)
> ftp.close
>
> It raised an exception for me:

For me too. Sorry, my fault. I should have first stripped down my
example to
the most simple case. I had, without noticing, caught that exception
before
passing control on to the caller.

Ronald
This topic is locked and can not be replied to.