apache/seatunnel · error · IOException
SftpException wrapped (pwd failed while deleting)
Error message
SftpException wrapped (pwd failed while deleting)
What it means
SFTPFileSystem.delete() first resolves the current remote working directory via channel.pwd(); if the SFTP server rejects that call the SftpException is wrapped in an IOException with no added context. It means the 'pwd' step failed while attempting a delete, typically because the underlying SSH/SFTP channel is dead, not authenticated, or the server errored.
Source
Thrown at seatunnel-connectors-v2/connector-file/connector-file-sftp/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/sftp/system/SFTPFileSystem.java:359
return !getFileStatus(channel, file).isDirectory();
} catch (FileNotFoundException e) {
return false; // file does not exist
} catch (IOException ioe) {
throw new IOException(E_FILE_CHECK_FAILED, ioe);
}
}
/**
* 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.
*/
private boolean delete(ChannelSftp channel, Path file, boolean recursive) throws IOException {
Path workDir;
try {
workDir = new Path(channel.pwd());
} catch (SftpException e) {
throw new IOException(e);
}
Path absolute = makeAbsolute(workDir, file);
String pathName = absolute.toUri().getPath();
FileStatus fileStat = null;
try {
fileStat = getFileStatus(channel, absolute);
} catch (FileNotFoundException e) {
// file not found, no need to delete, return true
return false;
}
if (!fileStat.isDirectory()) {
boolean status = true;
try {
channel.rm(pathName);
} catch (SftpException e) {
status = false;
}
return status;View on GitHub (pinned to cf67b549a7)
Solutions
- Check SFTP server connectivity and that the session/channel is still authenticated before the delete
- Reconnect (connect() / return channel to pool and re-acquire) and retry the delete
- Increase SSH keep-alive / ServerAliveInterval settings on the client to prevent idle disconnects
- Inspect the wrapped SftpException's id (e.g. SSH_FX_FAILURE vs SSH_FX_CONNECTION_LOST) to distinguish server error from dropped connection
Example fix
// before
boolean ok = fs.delete(new Path("/tmp/data/file.txt"), false);
// after
try {
boolean ok = fs.delete(new Path("/tmp/data/file.txt"), false);
} catch (IOException e) {
if (e.getCause() instanceof SftpException) {
// reconnect / retry delete
}
throw e;
} Defensive patterns
Strategy: try-catch
Validate before calling
boolean healthy = false;
try {
fs.getFileStatus(new Path("."));
healthy = true;
} catch (IOException e) {
healthy = false;
} Try / catch
try {
fs.delete(path, recursive);
} catch (IOException e) {
if (e.getCause() instanceof SftpException) { /* reconnect + retry */ }
throw e;
} Prevention
- Enable SSH keep-alive to avoid idle session drops
- Revalidate pooled channels before reuse
- Retry transient connection failures with backoff
- Monitor SFTP server session limits
When it happens
Trigger: Calling delete(path), delete(path, recursive) or a create() that deletes an existing file for overwrite, when channel.pwd() throws (session closed by server, connection dropped, auth expired, or server-side failure on the pwd request).
Common situations: SFTP session idle timeout between connect and delete; network interruption mid-job; server closes channel after MAX_SESSIONS limit; using a channel returned to the pool after failure; firewall dropping long-lived SSH connections.
Understand the failure class
Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.
Related errors
- SftpException wrapped (pwd failed while listing status)
- SFTP lstat failed for path=
- SFTP READDIR failed for path=
- File check failed
- SftpException wrapped (pwd failed while resolving file statu
AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10).
Data as JSON: /api/errors/0f82750922cb475a.
Report an issue: GitHub.