Skip Menu |

This queue is for tickets about the Net-SFTP-Foreign CPAN distribution.

Report information
The Basics
Id: 87220
Status: rejected
Priority: 0/
Queue: Net-SFTP-Foreign

People
Owner: Nobody in particular
Requestors: rduval [...] factset.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: setcwd unnecessarily canonicalizes the provided directory before issuing cwd command
Date: Tue, 23 Jul 2013 19:47:28 +0000
To: "bug-Net-SFTP-Foreign [...] rt.cpan.org" <bug-Net-SFTP-Foreign [...] rt.cpan.org>
From: Rob Duval <rduval [...] factset.com>
Hello, I am using Net::SFTP::Foreign in a Linux-based service, and so far it has been a great Perl interface to the OpenBSD SSH client. My implementation connects to a couple hundred different SFTP servers, mostly without issue. However, I am running into an issue when connecting to a server that identifies itself as Serv-U (http://www.serv-u.com/). When I connect to this server and attempt to use the setcwd command to change into a subdirectory, the method fails because the server does not support the SSH_FXP_REALPATH request, which canonicalizes a path per http://www.openssh.org/txt/draft-ietf-secsh-filexfer-02.txt. This struck me as odd behavior, because I expected Net::SFTP::Foreign to simply issue the cwd command without modifying the path, similar to how the OpenBSD SSH client works. I took a brief look at the Net::SFTP::Foreign source code, and it appears that the setcwd method calls realpath on the provided directory before issuing the cwd command. Even though it seems like almost all SFTP servers support the SSH_FXP_REALPATH request, I don't think it's necessary for setcwd to canonicalize the path. Would you please consider removing the realpath call from setcwd? The current implementation seems to be at odds with the OpenBSD SSH client's default behavior, so I think resolving this discrepancy would improve the module. Let me know if I can provide any other information, and thanks in advance. Rob Duval Senior Systems Engineer - Client Data Integration rduval@factset.com<mailto:rduval@factset.com> FactSet Research Systems Inc.<http://www.factset.com/>
Subject: Re: [rt.cpan.org #87220] setcwd unnecessarily canonicalizes the provided directory before issuing cwd command
Date: Tue, 23 Jul 2013 23:46:32 -0700 (PDT)
To: "bug-Net-SFTP-Foreign [...] rt.cpan.org" <bug-Net-SFTP-Foreign [...] rt.cpan.org>
From: Salvador Fandino <sfandino [...] yahoo.com>
Show quoted text
----- Original Message -----
> From: Rob Duval via RT <bug-Net-SFTP-Foreign@rt.cpan.org> > To: > Cc: > Sent: Tuesday, July 23, 2013 9:47 PM > Subject: [rt.cpan.org #87220] setcwd unnecessarily canonicalizes the provided directory before issuing cwd command > >T ue Jul 23 15:47:46 2013: Request 87220 was acted upon. > Transaction: Ticket created by rduval@factset.com >       Queue: Net-SFTP-Foreign >     Subject: setcwd unnecessarily canonicalizes the provided directory before > issuing cwd command >   Broken in: (no value) >     Severity: (no value) >       Owner: Nobody >   Requestors: rduval@factset.com >       Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=87220 > > > > Hello, > > I am using Net::SFTP::Foreign in a Linux-based service, and so far it has been a > great Perl interface to the OpenBSD SSH client.  My implementation connects to a > couple hundred different SFTP servers, mostly without issue. > > However, I am running into an issue when connecting to a server that identifies > itself as Serv-U (http://www.serv-u.com/).  When I connect to this server and > attempt to use the setcwd command to change into a subdirectory, the method > fails because the server does not support the SSH_FXP_REALPATH request, which > canonicalizes a path per > http://www.openssh.org/txt/draft-ietf-secsh-filexfer-02.txt. This struck me as > odd behavior, because I expected Net::SFTP::Foreign to simply issue the cwd > command without modifying the path, similar to how the OpenBSD SSH client works. > > I took a brief look at the Net::SFTP::Foreign source code, and it appears that > the setcwd method calls realpath on the provided directory before issuing the > cwd command.  Even though it seems like almost all SFTP servers support the > SSH_FXP_REALPATH request, I don't think it's necessary for setcwd to > canonicalize the path. > > Would you please consider removing the realpath call from setcwd?  The current > implementation seems to be at odds with the OpenBSD SSH client's default > behavior, so I think resolving this discrepancy would improve the module. > > Let me know if I can provide any other information, and thanks in advance.
OpenSSH sftp client also sends a realpath packet in order to canonicalize the directory. Can you activate debugging on the module and send me the output of a simple script that just connects to the Serv-U software and performs a setcwd operation? I.e:   use Net::SFTP::Foreign;   $Net::SFTP::Foreign::debug = -1;   my $sftp = Net::SFTP::Foreign->nw($host, ...)   $sftp->setcwd($target_dir); Then, run sftp in verbose mode (sftp -vvv host) and chdir into the same directory. Finally send me the output so that I can see what's being done differently.
Subject: RE: [rt.cpan.org #87220] setcwd unnecessarily canonicalizes the provided directory before issuing cwd command
Date: Wed, 24 Jul 2013 21:33:17 +0000
To: "bug-Net-SFTP-Foreign [...] rt.cpan.org" <bug-Net-SFTP-Foreign [...] rt.cpan.org>
From: Rob Duval <rduval [...] factset.com>

Message body is not shown because it is too large.

Subject: Re: [rt.cpan.org #87220] setcwd unnecessarily canonicalizes the provided directory before issuing cwd command
Date: Wed, 24 Jul 2013 23:58:19 -0700 (PDT)
To: "bug-Net-SFTP-Foreign [...] rt.cpan.org" <bug-Net-SFTP-Foreign [...] rt.cpan.org>
From: Salvador Fandino <sfandino [...] yahoo.com>
The difference between the two clients is that OpenSSH sftp client resolves the current directory '.' and then uses the response as the base for the following resolutions. In your session, for instance, it resolves first '.' as '/' and then '/data/' as '/data'. Net::SFTP::Foreign on the other hand, omits the current directory resolution, tries to resolve the relative path 'data' and fails. I think the following code could work:   my $sftp = Net::SFTP::Foreign->new($host, autodie => 1, ...);   $sftp->setcwd('.');   $sftp->setcwd('data');
Subject: RE: [rt.cpan.org #87220] setcwd unnecessarily canonicalizes the provided directory before issuing cwd command
Date: Thu, 25 Jul 2013 12:16:31 +0000
To: "bug-Net-SFTP-Foreign [...] rt.cpan.org" <bug-Net-SFTP-Foreign [...] rt.cpan.org>
From: Rob Duval <rduval [...] factset.com>
Hi Salva, Per your suggestion, the following code works: my $sftp = Net::SFTP::Foreign->new(..., autodie => 1); $sftp->setcwd('.'); $sftp->setcwd('data/'); print $sftp->cwd; However my service provides a single argument for the directory, so unfortunately I cannot use the above workaround at this time. I also tried the following code, but it did not work: my $sftp = Net::SFTP::Foreign->new(..., autodie => 1); $sftp->setcwd('./data/'); print $sftp->cwd; The above died with the same error: "Couldn't get realpath for remote 'data': No such file". If I turn off autodie, the setcwd appears to succeed, as cwd returns "/data" -- that might be worth looking into because even though the realpath request fails, cwd looks good. After trying another couple of combinations, it appears specifying the desired directory as '/data' (what the successful sequences evaluate to) avoids this problem, so I'll follow up with my consumer to see if they can change. Ideally I would expect what works in the OpenBSD client to work in Net::SFTP::Foreign, but I appreciate that there is a lot of nuance to the behavior. Thanks for the help, Rob Duval    Senior Systems Engineer - Client Data Integration    rduval@factset.com    FactSet Research Systems Inc. Show quoted text
-----Original Message----- From: Salvador \"Fandiño\" via RT [mailto:bug-Net-SFTP-Foreign@rt.cpan.org] Sent: Thursday, July 25, 2013 2:59 AM To: Rob Duval Subject: Re: [rt.cpan.org #87220] setcwd unnecessarily canonicalizes the provided directory before issuing cwd command <URL: https://rt.cpan.org/Ticket/Display.html?id=87220 > The difference between the two clients is that OpenSSH sftp client resolves the current directory '.' and then uses the response as the base for the following resolutions. In your session, for instance, it resolves first '.' as '/' and then '/data/' as '/data'. Net::SFTP::Foreign on the other hand, omits the current directory resolution, tries to resolve the relative path 'data' and fails. I think the following code could work:   my $sftp = Net::SFTP::Foreign->new($host, autodie => 1, ...);   $sftp->setcwd('.');   $sftp->setcwd('data');
Subject: Re: [rt.cpan.org #87220] setcwd unnecessarily canonicalizes the provided directory before issuing cwd command
Date: Thu, 25 Jul 2013 05:30:52 -0700 (PDT)
To: "bug-Net-SFTP-Foreign [...] rt.cpan.org" <bug-Net-SFTP-Foreign [...] rt.cpan.org>
From: Salvador Fandino <sfandino [...] yahoo.com>
Show quoted text
----- Original Message -----
> From: Rob Duval via RT <bug-Net-SFTP-Foreign@rt.cpan.org> > To: > Cc: > Sent: Thursday, July 25, 2013 2:16 PM > Subject: RE: [rt.cpan.org #87220] setcwd unnecessarily canonicalizes the provided directory before issuing cwd command > >       Queue: Net-SFTP-Foreign > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=87220 > > > Hi Salva, > > Per your suggestion, the following code works: > > my $sftp = Net::SFTP::Foreign->new(..., autodie => 1); > $sftp->setcwd('.'); > $sftp->setcwd('data/'); > print $sftp->cwd; > > However my service provides a single argument for the directory, so > unfortunately I cannot use the above workaround at this time.
Can't you just hard code the harmless $sftp->setcwd(".") call in your script? It is a do nothing operation for well behaved servers and would solve the issue you have with the Serv-U one. I am afraid I can not add it to Net::SFTP::Foreign, because as you have already found, servers have subtle behaviors related to path canonization and the change could break other people scripts.
Subject: RE: [rt.cpan.org #87220] setcwd unnecessarily canonicalizes the provided directory before issuing cwd command
Date: Thu, 25 Jul 2013 12:47:21 +0000
To: "bug-Net-SFTP-Foreign [...] rt.cpan.org" <bug-Net-SFTP-Foreign [...] rt.cpan.org>
From: Rob Duval <rduval [...] factset.com>
I'm afraid that I face a similar challenge -- if I decide to add that behavior, I risk disrupting > 1000 daily processes that connect to ~200 different SFTP servers. For now I'll see if the consumer can specify an absolute path, and then I'll look into hardcoding the $sftp->setcwd('.') if necessary. Thanks for the help -- this module has been really useful to my company. Rob Duval    Senior Systems Engineer - Client Data Integration    rduval@factset.com    FactSet Research Systems Inc. Show quoted text
-----Original Message----- From: Salvador \"Fandiño\" via RT [mailto:bug-Net-SFTP-Foreign@rt.cpan.org] Sent: Thursday, July 25, 2013 8:31 AM To: Rob Duval Subject: Re: [rt.cpan.org #87220] setcwd unnecessarily canonicalizes the provided directory before issuing cwd command <URL: https://rt.cpan.org/Ticket/Display.html?id=87220 >
----- Original Message -----
> From: Rob Duval via RT <bug-Net-SFTP-Foreign@rt.cpan.org> > To: > Cc: > Sent: Thursday, July 25, 2013 2:16 PM > Subject: RE: [rt.cpan.org #87220] setcwd unnecessarily canonicalizes the provided directory before issuing cwd command > >       Queue: Net-SFTP-Foreign > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=87220 > > > Hi Salva, > > Per your suggestion, the following code works: > > my $sftp = Net::SFTP::Foreign->new(..., autodie => 1); > $sftp->setcwd('.'); > $sftp->setcwd('data/'); > print $sftp->cwd; > > However my service provides a single argument for the directory, so > unfortunately I cannot use the above workaround at this time.
Can't you just hard code the harmless $sftp->setcwd(".") call in your script? It is a do nothing operation for well behaved servers and would solve the issue you have with the Serv-U one. I am afraid I can not add it to Net::SFTP::Foreign, because as you have already found, servers have subtle behaviors related to path canonization and the change could break other people scripts.
Subject: Re: [rt.cpan.org #87220] setcwd unnecessarily canonicalizes the provided directory before issuing cwd command
Date: Thu, 25 Jul 2013 06:25:06 -0700 (PDT)
To: "bug-Net-SFTP-Foreign [...] rt.cpan.org" <bug-Net-SFTP-Foreign [...] rt.cpan.org>
From: Salvador Fandino <sfandino [...] yahoo.com>
Show quoted text
----- Original Message -----
> From: Rob Duval via RT <bug-Net-SFTP-Foreign@rt.cpan.org> > To: > Cc: > Sent: Thursday, July 25, 2013 2:47 PM > Subject: RE: [rt.cpan.org #87220] setcwd unnecessarily canonicalizes the provided directory before issuing cwd command > >       Queue: Net-SFTP-Foreign > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=87220 > > > I'm afraid that I face a similar challenge -- if I decide to add that > behavior, I risk disrupting > 1000 daily processes that connect to ~200 > different SFTP servers.  For now I'll see if the consumer can specify an > absolute path, and then I'll look into hardcoding the > $sftp->setcwd('.') if necessary.
Maybe you can implement a fallback approach. Try setting the cwd to the one given, if that fails, set the cwd to '.' and try setting the cwd to the one given again.
Subject: RE: [rt.cpan.org #87220] setcwd unnecessarily canonicalizes the provided directory before issuing cwd command
Date: Thu, 25 Jul 2013 13:37:07 +0000
To: "bug-Net-SFTP-Foreign [...] rt.cpan.org" <bug-Net-SFTP-Foreign [...] rt.cpan.org>
From: Rob Duval <rduval [...] factset.com>
That is a good idea -- I will give that a shot as well. Rob Duval    Senior Systems Engineer - Client Data Integration    rduval@factset.com    FactSet Research Systems Inc. Show quoted text
-----Original Message----- From: Salvador \"Fandiño\" via RT [mailto:bug-Net-SFTP-Foreign@rt.cpan.org] Sent: Thursday, July 25, 2013 9:25 AM To: Rob Duval Subject: Re: [rt.cpan.org #87220] setcwd unnecessarily canonicalizes the provided directory before issuing cwd command <URL: https://rt.cpan.org/Ticket/Display.html?id=87220 >
----- Original Message -----
> From: Rob Duval via RT <bug-Net-SFTP-Foreign@rt.cpan.org> > To: > Cc: > Sent: Thursday, July 25, 2013 2:47 PM > Subject: RE: [rt.cpan.org #87220] setcwd unnecessarily canonicalizes the provided directory before issuing cwd command > >       Queue: Net-SFTP-Foreign > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=87220 > > > I'm afraid that I face a similar challenge -- if I decide to add that > behavior, I risk disrupting > 1000 daily processes that connect to ~200 > different SFTP servers.  For now I'll see if the consumer can specify an > absolute path, and then I'll look into hardcoding the > $sftp->setcwd('.') if necessary.
Maybe you can implement a fallback approach. Try setting the cwd to the one given, if that fails, set the cwd to '.' and try setting the cwd to the one given again.
The bug is on the server side. Closing.