{"record":{"id":"14b289b528815e4b","repo":"pentaho/pentaho-kettle","slug":"failed-to-get-file-size","errorCode":null,"errorMessage":"Failed to get file size: ","messagePattern":"Failed to get file size: ","errorType":"exception","errorClass":"SftpException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/core/ssh/mina/MinaSftpSession.java","lineNumber":79,"sourceCode":"      return false;\n    }\n  }\n\n  @Override\n  public boolean isDirectory( String path ) throws SftpException {\n    try {\n      return client.stat( path ).isDirectory();\n    } catch ( IOException e ) {\n      throw new SftpException( \"Failed to check if path is directory: \" + path, e );\n    }\n  }\n\n  @Override\n  public long size( String path ) throws SftpException {\n    try {\n      return client.stat( path ).getSize();\n    } catch ( IOException e ) {\n      throw new SftpException( \"Failed to get file size: \" + path, e );\n    }\n  }\n\n  @Override\n  public void download( String remote, OutputStream target ) throws SftpException {\n    try {\n      try ( InputStream in = client.read( remote ) ) {\n        in.transferTo( target );\n      }\n    } catch ( IOException e ) {\n      throw new SftpException( \"Failed to download file: \" + remote, e );\n    }\n  }\n\n  @Override\n  public void upload( InputStream source, String remote, boolean overwrite ) throws SftpException {\n    try {\n      try ( SftpClient.CloseableHandle h = client.open( remote, SftpClient.OpenMode.Write, SftpClient.OpenMode.Create,","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/core/ssh/mina/MinaSftpSession.java#L61-L97","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Confirm the exact remote path exists (case-sensitive) before calling size()","Check read permissions for the SSH user on the file and its directory","Reconnect the session if it was idle-closed by the server or firewall","Read e.getCause() to distinguish no-such-file from permission-denied"],"exampleFix":"// before\nlong sz = session.size(remotePath);\n// after\ntry {\n  long sz = session.size(remotePath);\n} catch (SftpException e) {\n  throw new RuntimeException(\"Cannot stat remote file '\" + remotePath + \"': \" + e.getCause(), e);\n}","handlingStrategy":"try-catch","validationCode":"// pre-check existence and connectivity\nif (!session.isConnected()) { session.connect(); }\ntry { session.size(remotePath); System.out.println(\"file present\"); }\ncatch (SftpException e) { System.out.println(\"missing/unreadable: \" + remotePath); }","typeGuard":"Long safeSize(MinaSftpSession s, String p) {\n  try { return s.size(p); } catch (SftpException e) { return null; }\n}","tryCatchPattern":"try {\n  long sz = session.size(remotePath);\n} catch (SftpException e) {\n  throw new IllegalStateException(\"Remote file missing or unreadable: \" + remotePath + \" cause=\" + e.getCause(), e);\n}","preventionTips":["Remember remote filesystems are case-sensitive; verify exact filenames","Wait for file completeness (size stable across polls) before stat in producer/consumer flows","Reconnect idle sessions before size checks","Check read permissions on the file and its parent directory"],"tags":["sftp","ssh","file-not-found","io"],"backgroundTag":"file-not-found","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}