{"record":{"id":"7f13415c6a6c5e95","repo":"apache/seatunnel","slug":"sftpexception-wrapped-pwd-failed-while-renaming","errorCode":null,"errorMessage":"SftpException wrapped (pwd failed while renaming)","messagePattern":"SftpException wrapped \\(pwd failed while renaming\\)","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":439,"sourceCode":"        }\n        ArrayList<FileStatus> fileStats = new ArrayList<FileStatus>();\n        for (int i = 0; i < sftpFiles.size(); i++) {\n            LsEntry entry = sftpFiles.get(i);\n            String fname = entry.getFilename();\n            // skip current and parent directory, ie. \".\" and \"..\"\n            if (!\".\".equalsIgnoreCase(fname) && !\"..\".equalsIgnoreCase(fname)) {\n                fileStats.add(getFileStatus(client, entry, absolute));\n            }\n        }\n        return fileStats.toArray(new FileStatus[fileStats.size()]);\n    }\n\n    private boolean rename(ChannelSftp channel, Path src, Path dst) throws IOException {\n        Path workDir;\n        try {\n            workDir = new Path(channel.pwd());\n        } catch (SftpException e) {\n            throw new IOException(e);\n        }\n        Path absoluteSrc = makeAbsolute(workDir, src);\n        Path absoluteDst = makeAbsolute(workDir, dst);\n\n        if (!exists(channel, absoluteSrc)) {\n            throw new IOException(String.format(E_SPATH_NOTEXIST, src));\n        }\n        if (exists(channel, absoluteDst)) {\n            throw new IOException(String.format(E_DPATH_EXIST, dst));\n        }\n        boolean renamed = true;\n        try {\n            final String previousCwd = channel.pwd();\n            channel.cd(\"/\");\n            channel.rename(src.toUri().getPath(), dst.toUri().getPath());\n            channel.cd(previousCwd);\n        } catch (SftpException e) {\n            renamed = false;","sourceCodeStart":421,"sourceCodeEnd":457,"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#L421-L457","documentation":"rename() resolves the working directory via channel.pwd() before making src/dst absolute; if pwd throws, the SftpException is wrapped in an IOException. This happens before any existence checks, so it indicates the channel/server was already in a bad state when the rename started.","triggerScenarios":"fs.rename(src, dst) (commit phase, file-move steps) when the SFTP session is closed, authentication expired, or the server fails the pwd request.","commonSituations":"Session idle timeout before the job's commit/rename step; server restart between write and rename; stale pooled channel; firewall dropping long-lived SSH control connection.","solutions":["Reconnect and retry the rename","Enable SSH keep-alive (ServerAliveInterval) to keep the session alive across job phases","Check the wrapped SftpException id to diagnose server vs transport failure","Ensure channels are returned to the pool and revalidated before reuse"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"try {\n    fs.exists(new Path(\"/\")); // channel health probe\n} catch (IOException e) {\n    reconnect();\n}","typeGuard":null,"tryCatchPattern":"try {\n    fs.rename(src, dst);\n} catch (IOException e) {\n    if (e.getCause() instanceof SftpException) { reconnect(); /* retry rename */ }\n    throw e;\n}","preventionTips":["Keep the session alive during long write phases (keep-alive)","Revalidate the channel right before commit-time renames","Make renames retry-safe and idempotent"],"tags":["sftp","rename","connection"],"backgroundTag":"connection-refused","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"}