apache/seatunnel · error · IOException

SftpException wrapped (pwd failed while resolving file statu

Error message

SftpException wrapped (pwd failed while resolving file status)

What it means

Inside getFileStatus(), the code first resolves the server working directory with client.pwd(). If pwd() throws an SftpException, it is wrapped into a plain IOException with no message. This means the SFTP server refused (or the channel could not serve) the 'pwd' request, so the file's absolute path could not be computed.

Source

Thrown at seatunnel-connectors-v2/connector-file/connector-file-sftp/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/sftp/system/SFTPFileSystem.java:197

            }
            _path2[j++] = b;
        }
        return new String(_path2, 0, _path2.length, StandardCharsets.UTF_8);
    }

    /**
     * Convenience method, so that we don't open a new connection when using this method from within
     * another method. Otherwise every API invocation incurs the overhead of opening/closing a TCP
     * connection.
     */
    @SuppressWarnings("unchecked")
    private FileStatus getFileStatus(ChannelSftp client, Path file) throws IOException {
        FileStatus fileStat = null;
        Path workDir;
        try {
            workDir = new Path(client.pwd());
        } catch (SftpException e) {
            throw new IOException(e);
        }
        Path absolute = makeAbsolute(workDir, file);
        Path parentPath = absolute.getParent();
        if (parentPath == null) { // root directory
            long length = -1; // Length of root directory on server not known
            boolean isDir = true;
            int blockReplication = 1;
            long blockSize = DEFAULT_BLOCK_SIZE; // Block Size not known.
            long modTime = -1; // Modification time of root directory not known.
            Path root = new Path("/");
            return new FileStatus(
                    length,
                    isDir,
                    blockReplication,
                    blockSize,
                    modTime,
                    root.makeQualified(this.getUri(), this.getWorkingDirectory()));
        }

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Reconnect/re-open the SFTP channel before calling file-system operations
  2. Confirm the channel is connected (client.isConnected()) and the session is authenticated
  3. Test pwd with an interactive sftp client using the same account and chroot setup
  4. Upgrade/align the JSch version if the server's SFTP protocol version is incompatible
  5. Check server logs for SSH_FXP_REALPATH failures

Example fix

// before
FileStatus st = fs.getFileStatus(path); // IOException wrapping SftpException from pwd()
// after
if (channel == null || !channel.isConnected()) {
    channel = openConnectedChannel(conf); // re-establish before use
}
FileStatus st = fs.getFileStatus(path);
Defensive patterns

Strategy: try-catch

Validate before calling

if (channel == null || !channel.isConnected()) { channel = openConnectedChannel(conf); } // then optionally: channel.pwd(); as a health probe

Try / catch

try { workDir = new Path(client.pwd()); } catch (SftpException e) { throw new IOException("pwd failed: sftp code " + e.id, e); }

Prevention

When it happens

Trigger: getFileStatus() (reached via exists, fstat, isFile, delete, fileStat, status) is invoked on an SFTP channel whose session is dead, not connected, or whose server rejects SSH_FXP_REALPATH used by pwd().

Common situations: Channel reused after disconnect; server-side chroot or restricted shell blocks realpath; SSH session timed out between operations; server software incompatible with the JSch pwd implementation.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/53b24a637f2871bb. Report an issue: GitHub.