{"record":{"id":"6bc035ab73b30914","repo":"apache/hadoop","slug":"failed-to-get-home-directory","errorCode":null,"errorMessage":"Failed to get home directory","messagePattern":"Failed to get home directory","errorType":"exception","errorClass":"FTPException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ftp/FTPFileSystem.java","lineNumber":721,"sourceCode":"    boolean renamed = client.rename(from, to);\n    return renamed;\n  }\n\n  @Override\n  public Path getWorkingDirectory() {\n    // Return home directory always since we do not maintain state.\n    return getHomeDirectory();\n  }\n\n  @Override\n  public Path getHomeDirectory() {\n    FTPClient client = null;\n    try {\n      client = connect();\n      Path homeDir = new Path(client.printWorkingDirectory());\n      return homeDir;\n    } catch (IOException ioe) {\n      throw new FTPException(\"Failed to get home directory\", ioe);\n    } finally {\n      try {\n        disconnect(client);\n      } catch (IOException ioe) {\n        throw new FTPException(\"Failed to disconnect\", ioe);\n      }\n    }\n  }\n\n  @Override\n  public void setWorkingDirectory(Path newDir) {\n    // we do not maintain the working directory state\n  }\n}\n","sourceCodeStart":703,"sourceCodeEnd":736,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ftp/FTPFileSystem.java#L703-L736","documentation":"getHomeDirectory() opens a fresh FTP connection, issues PWD to learn the login directory, and returns it as a Path. Any IOException during connect, login, or PWD is wrapped as FTPException(\"Failed to get home directory\") with the cause preserved. Because FTPFileSystem keeps no state, getWorkingDirectory() delegates here too, so this error can surface from many entry points.","triggerScenarios":"connect() failing — unknown host, wrong port, connection refused, failed login — or printWorkingDirectory() failing after login because the server rejected PWD.","commonSituations":"Misconfigured fs.defaultFS (wrong scheme, missing port); credentials not set via fs.ftp.user.<host>/fs.ftp.password.<host> or keyfile fs.ftp.keypair.encrypted; firewall blocking control port 21 or the passive data port range; server requiring FTPS while the client is set up for plain FTP.","solutions":["Read exception.getCause(): UnknownHostException vs ConnectException vs login failure points to DNS vs network vs credentials","Test the exact URI and credentials with an external FTP client from the same host","Set fs.ftp.user.<host>, fs.ftp.password.<host> (or fs.ftp.keypair.encrypted) in the Configuration","Open control port 21 and the server's passive data port range in every firewall on the path","If the server requires FTPS/TLS, align the endpoint and credential setup, then retest"],"exampleFix":"// before\nconf.set(\"fs.defaultFS\", \"ftp://ftp.example.com/\");  // no credentials -> FTPException\n\n// after\nconf.set(\"fs.defaultFS\", \"ftp://ftp.example.com/\");\nconf.set(\"fs.ftp.user.ftp.example.com\", \"uploader\");\nconf.set(\"fs.ftp.password.ftp.example.com\", \"******\");  // or fs.ftp.keypair.encrypted","handlingStrategy":"try-catch","validationCode":"// cheap probe before relying on the filesystem\ntry {\n  fs.exists(new Path(\"/\"));\n} catch (IOException e) {\n  throw new RuntimeException(\"FTP endpoint unusable; check host/port/credentials\", e);\n}","typeGuard":null,"tryCatchPattern":"catch FTPException(\"Failed to get home directory\"), switch on getCause(): UnknownHostException -> fix host; ConnectException -> fix port/firewall; login failure -> fix fs.ftp.user/password config; then rebuild the FileSystem.","preventionTips":["Set fs.ftp.user.<host> and fs.ftp.password.<host> (or keypair) in Configuration before use","Smoke-test the endpoint with an external FTP client from the same network","Open control port 21 and the passive data port range in firewalls"],"tags":["ftp","hadoop","connection","configuration"],"backgroundTag":"ftp-connection-failure","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}