pentaho/pentaho-kettle · error · SftpException

Failed to get file size:

Error message

Failed to get file size: 

What it means

MinaSftpSession.size() wraps IOException from client.stat(path).getSize() into an SftpException. The file size could not be read, most often because the remote file does not exist or is not accessible. The wrapped IOException holds the actual server-side reason.

Solutions

  1. Confirm the exact remote path exists (case-sensitive) before calling size()
  2. Check read permissions for the SSH user on the file and its directory
  3. Reconnect the session if it was idle-closed by the server or firewall
  4. Read e.getCause() to distinguish no-such-file from permission-denied

Example fix

// before
long sz = session.size(remotePath);
// after
try {
  long sz = session.size(remotePath);
} catch (SftpException e) {
  throw new RuntimeException("Cannot stat remote file '" + remotePath + "': " + e.getCause(), e);
}
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check existence and connectivity
if (!session.isConnected()) { session.connect(); }
try { session.size(remotePath); System.out.println("file present"); }
catch (SftpException e) { System.out.println("missing/unreadable: " + remotePath); }

Type guard

Long safeSize(MinaSftpSession s, String p) {
  try { return s.size(p); } catch (SftpException e) { return null; }
}

Try / catch

try {
  long sz = session.size(remotePath);
} catch (SftpException e) {
  throw new IllegalStateException("Remote file missing or unreadable: " + remotePath + " cause=" + e.getCause(), e);
}

Prevention

When it happens

Trigger: Calling size(path) on a nonexistent remote file, on a path the user cannot read, or after the SFTP channel/session was closed by the server or network.

Common situations: Checking a download's size before transfer when the filename is wrong or casing differs (case-sensitive remote filesystems), automations racing with file producers so the file is not yet written, or credentials lacking read access.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/14b289b528815e4b. Report an issue: GitHub.

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/core/ssh/mina/MinaSftpSession.java:79

      return false;
    }
  }

  @Override
  public boolean isDirectory( String path ) throws SftpException {
    try {
      return client.stat( path ).isDirectory();
    } catch ( IOException e ) {
      throw new SftpException( "Failed to check if path is directory: " + path, e );
    }
  }

  @Override
  public long size( String path ) throws SftpException {
    try {
      return client.stat( path ).getSize();
    } catch ( IOException e ) {
      throw new SftpException( "Failed to get file size: " + path, e );
    }
  }

  @Override
  public void download( String remote, OutputStream target ) throws SftpException {
    try {
      try ( InputStream in = client.read( remote ) ) {
        in.transferTo( target );
      }
    } catch ( IOException e ) {
      throw new SftpException( "Failed to download file: " + remote, e );
    }
  }

  @Override
  public void upload( InputStream source, String remote, boolean overwrite ) throws SftpException {
    try {
      try ( SftpClient.CloseableHandle h = client.open( remote, SftpClient.OpenMode.Write, SftpClient.OpenMode.Create,

View on GitHub (pinned to f3058517a1)