{"record":{"id":"ad361663576e4af6","repo":"pentaho/pentaho-kettle","slug":"for-a-sftp-connection-server-name-and-username-must-be-set","errorCode":null,"errorMessage":"For a SFTP connection server name and username must be set and server port must be greater than zero.","messagePattern":"For a SFTP connection server name and username must be set and server port must be greater than zero\\.","errorType":"validation","errorClass":"KettleJobException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/job/entries/sftp/SFTPClient.java","lineNumber":137,"sourceCode":"   * @param bowl\n   *          Bowl providing context for File operations\n   * @param serverIP\n   *          IP address of remote server\n   * @param serverPort\n   *          port of remote server\n   * @param userName\n   *          username of remote server\n   * @param privateKeyFilename\n   *          filename of private key\n   * @param passPhrase\n   *          passphrase\n   * @throws KettleJobException\n   */\n  public SFTPClient( Bowl bowl, InetAddress serverIP, int serverPort, String userName, String privateKeyFilename,\n    String passPhrase ) throws KettleJobException {\n\n    if ( serverIP == null || serverPort <= 0 || userName == null || userName.equals( \"\" ) ) {\n      throw new KettleJobException(\n        \"For a SFTP connection server name and username must be set and server port must be greater than zero.\" );\n    }\n\n    this.serverIP = serverIP;\n    this.serverPort = serverPort;\n    this.userName = userName;\n    this.bowl = bowl;\n\n    JSch jsch = createJSch();\n    try {\n      if ( !Utils.isEmpty( privateKeyFilename ) ) {\n        // We need to use private key authentication\n        this.prvkey = privateKeyFilename;\n\n        byte[] passPhraseBytes;\n        if ( !Utils.isEmpty( passPhrase ) ) {\n          // Set passphrase\n          this.passphrase = passPhrase;","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/job/entries/sftp/SFTPClient.java#L119-L155","documentation":"The SFTPClient constructor validates connection parameters before connecting: a non-null server IP, a port greater than zero, and a non-empty username are all mandatory. If any is missing it throws this KettleJobException with a literal message describing the requirements.","triggerScenarios":"new SFTPClient(bowl, null, port, user, ...) with serverIP null; port <= 0; or userName null or empty string.","commonSituations":"SFTP job entry fields not filled in (server name empty, port left 0 or -1); variables resolving to empty strings at runtime; programmatic use of SFTPClient without resolving the hostname to an InetAddress.","solutions":["Fill in the SFTP job entry's server name, port, and username fields.","Resolve the host with InetAddress.getByName(host) before constructing SFTPClient and check it is non-null.","Default the port to 22 when unset and validate port is an integer > 0.","Trim the username and reject empty strings before instantiating."],"exampleFix":"// before\nSFTPClient c = new SFTPClient(bowl, null, 0, \"\", null, null);\n// after\nInetAddress ip = InetAddress.getByName(\"sftp.example.com\");\nif (ip == null || port <= 0 || user == null || user.isEmpty()) throw new IllegalArgumentException(\"bad sftp config\");\nSFTPClient c = new SFTPClient(bowl, ip, port, user, null, null);","handlingStrategy":"validation","validationCode":"InetAddress ip = InetAddress.getByName(host); // throws UnknownHostException early\nif (ip == null || serverPort <= 0 || userName == null || userName.trim().isEmpty()) {\n  throw new IllegalArgumentException(\"SFTP requires server, port>0 and username\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  new SFTPClient(bowl, ip, port, user, key, passphrase);\n} catch (KettleJobException e) {\n  logError(\"SFTP config invalid: \" + e.getMessage());\n}","preventionTips":["Require host, port, and username fields before saving the job entry.","Default port to 22 and clamp to 1-65535.","Trim and validate the username at design time."],"tags":["sftp","validation","configuration","constructor"],"backgroundTag":"missing-required-argument","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"}