bamaer opened a new issue, #9033:
URL: https://github.com/apache/hop/issues/9033

   ### Apache Hop version?
   
   2.20.0-SNAPSHOT
   
   ### Java version?
   
   21
   
   ### Operating system
   
   Windows
   
   ### What happened?
   
   ### Problem
   
   Since #8886, a path such as `//HLQ.APP.PREFIX/MEMBER` addresses an MVS data 
set on a z/OS SFTP server. A path with only a single level after the double 
slash doesn't work, for example `//HLQ.APP.PREFIX`. That's typically the remote 
folder of the SFTP Put transform.
   
   The SFTP Put transform fails with:
   
   ```
   Unable to find remote folder [//HLQ.APP.PREFIX/]
   ```
   
   The same upload works from the OpenSSH `sftp` client (`cd //HLQ.APP.PREFIX`, 
`put FILE`).
   
   ### Cause
   
   Hop sends the correct path. jsch rewrites it: almost every `ChannelSftp` 
method (`stat`, `cd`, `ls`, `mkdir`, `put`, `get`, `rm`, ...) passes the path 
through `glob_remote`, which splits it at the last slash:
   
   ```java
   String dir = _path.substring(0, ((foo == 0) ? 1 : foo));   // "//X" -> dir = 
"/"
   ...
   if (!dir.equals("/")) dir += "/";
   v.addElement(dir + Util.unquote(_pattern));                // -> "/X"
   ```
   
   For `//X`, the last slash is the second one, so `dir` becomes `/` and the 
server is asked for `/X`, a USS path. Paths with two or more levels (`//X/Y`) 
aren't affected. jsch's public API offers no way to send exactly `//X`. Seen 
with jsch 2.28.6.
   
   ### Fix
   
   `SftpFileObject.remotePath` adds a trailing slash to a single-level path 
rooted at a second slash: `//X` becomes `//X/`. The last slash then comes after 
the data set name, and jsch passes the path through unchanged. Ordinary paths 
and multi-level data set paths are untouched. Because every SFTP request uses 
this path, the fix covers the SFTP Put transform, Process Files and anything 
else that goes through the SFTP VFS provider.
   
   Verified against a z/OS SFTP server: the folder check passes and the upload 
to `//HLQ.APP.PREFIX/NEWNAME` succeeds.
   
   ### Follow-ups
   
   - **Clearer error when the target exists but isn't a file.** If 
`//HLQ.APP.PREFIX/NAME` already exists and z/OS reports it as a directory (an 
existing data set, or a name with other data sets below it), the upload fails 
with commons-vfs `Could not create file "..."`. There's no cause and no hint at 
the reason. SFTP Put should check for this and say so.
   - **Root cause missing from error rows.** With error handling enabled, SFTP 
Put sends `e.toString()` to the error stream. That holds only the first two 
exception messages, so the server's answer (e.g. `4: SSH_FX_FAILURE`) never 
shows up.
   - **Invalid data set names fail with a generic "Failure".** A remote file 
name that isn't a valid MVS qualifier (more than 8 characters, or characters 
outside `A-Z 0-9 @ # $`) makes z/OS reject the `OPEN` with a bare 
`SSH_FX_FAILURE`. A hint in the error message for `//` paths would save a lot 
of guessing.
   - **Workflow actions using `SftpClient` directly.** `ActionSftpPut` calls 
`SftpClient.folderExists` and `chdir` on the raw folder string, which go 
through the same jsch rewrite. A single-level `//X` folder is likely broken 
there too.
   - **Upstream.** Report the `glob_remote` behaviour to 
[mwiede/jsch](https://github.com/mwiede/jsch), so a path with exactly two 
leading slashes keeps them.
   
   
   ### Issue Priority
   
   Priority: 2
   
   ### Issue Component
   
   Component: Transforms, Component: Metadata


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to