sshtools / maverick-synergy

Next Generation Java SSH API
https://jadaptive.com
GNU Lesser General Public License v3.0
96 stars 26 forks source link

'/' is getting removed from directory path #83

Open Prashant2603 opened 11 months ago

Prashant2603 commented 11 months ago

For one of our use case where we are trying to connect to a sftp server we can see some weird behavior. In this particular case SFTP server allows cd command only with a '/' at end

  1. cd dirA/dirB/ - works
  2. cd dirA/dirB - does not work When we try calling sftpClient.cd("dirA/dirB/") it attempts to call cd dirA/dirB and fails. We tried to look into your code and it seems like '/' is removed intentionally. Can someone explain what is the reason for that and can we have some workaround to cd/list with '/' at the end
Prashant2603 commented 11 months ago

@ludup @brett-smith @dandalf Could someone help me here? Everywhere in code I see // Remove trailing forward slash if (absolutePath.endsWith("/")) { absolutePath = absolutePath.substring(0, absolutePath.length() - 1); }

ludup commented 9 months ago

How many servers are affected by this? This is a long-standing behaviour I've not had reports about before, and this code goes back to previous generations. The furthest I can go back to is the initial commit of Maverick Legacy to private git in 2015, which still appears to do this. If I'd had a problem supporting commercial customers since that commit, there would already be a switch there.

You could propose a change to implement a configuration switch. Look at AdaptiveConfiguration, While it's not used much at the moment in Synergy, the plan is to move all configurations over to using it to match the legacy API flexibility.

ludup commented 7 months ago

With the 3.1.2-SNAPSHOT, you can -Dmaverick.disableSlashRemoval=true to remove the path processing.

As stated before, this code has existed for a long time and in all the years I've supported the various APIs it has not come up as a problem before. Its inclusion would suggest my former self had good reason for doing it.

You can now disable it system-wide with this system property switch. Please let us know if you encounter any problems with this switch enabled.

In a future release (3.2), it will be possible to configure this per connection through the planned extension of the Adaptive configuration file. However, if you need this before you could always modify the SftpClient to have a boolean option set on individual instances.