{"record":{"id":"53b24a637f2871bb","repo":"apache/seatunnel","slug":"sftpexception-wrapped-pwd-failed-while-resolving","errorCode":null,"errorMessage":"SftpException wrapped (pwd failed while resolving file status)","messagePattern":"SftpException wrapped \\(pwd failed while resolving file status\\)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-file/connector-file-sftp/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/sftp/system/SFTPFileSystem.java","lineNumber":197,"sourceCode":"            }\n            _path2[j++] = b;\n        }\n        return new String(_path2, 0, _path2.length, StandardCharsets.UTF_8);\n    }\n\n    /**\n     * Convenience method, so that we don't open a new connection when using this method from within\n     * another method. Otherwise every API invocation incurs the overhead of opening/closing a TCP\n     * connection.\n     */\n    @SuppressWarnings(\"unchecked\")\n    private FileStatus getFileStatus(ChannelSftp client, Path file) throws IOException {\n        FileStatus fileStat = null;\n        Path workDir;\n        try {\n            workDir = new Path(client.pwd());\n        } catch (SftpException e) {\n            throw new IOException(e);\n        }\n        Path absolute = makeAbsolute(workDir, file);\n        Path parentPath = absolute.getParent();\n        if (parentPath == null) { // root directory\n            long length = -1; // Length of root directory on server not known\n            boolean isDir = true;\n            int blockReplication = 1;\n            long blockSize = DEFAULT_BLOCK_SIZE; // Block Size not known.\n            long modTime = -1; // Modification time of root directory not known.\n            Path root = new Path(\"/\");\n            return new FileStatus(\n                    length,\n                    isDir,\n                    blockReplication,\n                    blockSize,\n                    modTime,\n                    root.makeQualified(this.getUri(), this.getWorkingDirectory()));\n        }","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-file/connector-file-sftp/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/sftp/system/SFTPFileSystem.java#L179-L215","documentation":"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.","triggerScenarios":"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().","commonSituations":"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.","solutions":["Reconnect/re-open the SFTP channel before calling file-system operations","Confirm the channel is connected (client.isConnected()) and the session is authenticated","Test pwd with an interactive sftp client using the same account and chroot setup","Upgrade/align the JSch version if the server's SFTP protocol version is incompatible","Check server logs for SSH_FXP_REALPATH failures"],"exampleFix":"// before\nFileStatus st = fs.getFileStatus(path); // IOException wrapping SftpException from pwd()\n// after\nif (channel == null || !channel.isConnected()) {\n    channel = openConnectedChannel(conf); // re-establish before use\n}\nFileStatus st = fs.getFileStatus(path);","handlingStrategy":"try-catch","validationCode":"if (channel == null || !channel.isConnected()) { channel = openConnectedChannel(conf); } // then optionally: channel.pwd(); as a health probe","typeGuard":null,"tryCatchPattern":"try { workDir = new Path(client.pwd()); } catch (SftpException e) { throw new IOException(\"pwd failed: sftp code \" + e.id, e); }","preventionTips":["Probe with pwd() before batches of operations","Reconnect stale channels","Verify chroot/restricted-shell setup for the account","Align JSch and server SFTP protocol versions","Check server logs for realpath failures"],"tags":["sftp","pwd","sftpexception","connection"],"backgroundTag":"network-request-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}