{"record":{"id":"151d0f3f82d49135","repo":"apache/seatunnel","slug":"unable-to-open-file-file-aborting","errorCode":null,"errorMessage":"Unable to open file: ${file}, Aborting","messagePattern":"Unable to open file: (.+?), Aborting","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-file/connector-file-ftp/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/ftp/system/SeaTunnelFTPFileSystem.java","lineNumber":328,"sourceCode":"            throw new FileNotFoundException(\"Path \" + file + \" is a directory.\");\n        }\n        client.allocate(bufferSize);\n        Path parent = absolute.getParent();\n        // Change to parent directory on the\n        // server. Only then can we read the\n        // file\n        // on the server by opening up an InputStream. As a side effect the working\n        // directory on the server is changed to the parent directory of the file.\n        // The FTP client connection is closed when close() is called on the\n        // FSDataInputStream.\n        client.changeWorkingDirectory(parent.toUri().getPath());\n        InputStream is = client.retrieveFileStream(file.getName());\n        FSDataInputStream fis = new FSDataInputStream(new FTPInputStream(is, client, statistics));\n        if (!FTPReply.isPositivePreliminary(client.getReplyCode())) {\n            // The ftpClient is an inconsistent state. Must close the stream\n            // which in turn will logout and disconnect from FTP server\n            fis.close();\n            throw new IOException(\"Unable to open file: \" + file + \", Aborting\");\n        }\n        return fis;\n    }\n\n    /**\n     * A stream obtained via this call must be closed before using other APIs of this class or else\n     * the invocation will block.\n     */\n    @Override\n    public FSDataOutputStream create(\n            Path file,\n            FsPermission permission,\n            boolean overwrite,\n            int bufferSize,\n            short replication,\n            long blockSize,\n            Progressable progress)\n            throws IOException {","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-file/connector-file-ftp/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/ftp/system/SeaTunnelFTPFileSystem.java#L310-L346","documentation":"SeaTunnelFTPFileSystem.open() issues RETR via client.retrieveFileStream(); the FSDataInputStream is constructed first, but if the server's reply code is not a positive preliminary (1xx) response, the client is in an inconsistent state. The stream is closed (logging out/disconnecting) and IOException('Unable to open file: <file>, Aborting') is thrown.","triggerScenarios":"Calling open(file) when the FTP server answers RETR with a non-1xx reply: file not retrievable (permissions, not found at the server side due to changed working directory), server refuses transfer, or data connection cannot be established (firewall blocking passive/active mode).","commonSituations":"File removed between listing and open; FTP user lacks read permission; firewall/NAT breaks the data channel (common fix: switch ftp.connection.mode between active/passive); server-side transfer restrictions (e.g. TLS required).","solutions":["Check FTP server logs for the RETR reply code to see why the transfer was refused","Toggle ftp.connection.mode between active and passive to work through the firewall/NAT","Verify the FTP user has read permission on the file and execute permission on parent directories","Confirm the file still exists at open time (it may have been deleted or renamed between listing and read)"],"exampleFix":"// before\n\"ftp.connection.mode\" = \"active\" // corporate NAT blocks the active data connection\n// after\n\"ftp.connection.mode\" = \"passive\"","handlingStrategy":"try-catch","validationCode":"// Preflight RETR check via a plain FTP client\nFTPClient c = connect();\nboolean ok = c.retrieveFile(file.getName(), NullOutputStream.INSTANCE);\nint reply = c.getReplyCode();\ndisconnect(c);\nif (!ok) throw new IllegalStateException(\"FTP server refuses RETR for \" + file.getName() + \", reply=\" + reply);","typeGuard":null,"tryCatchPattern":"try {\n    return fs.open(path);\n} catch (IOException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Unable to open file\")) {\n        LOG.warn(\"RETR failed for {} (reply non-1xx); check perms/firewall/mode\", path, e);\n        // retry with alternate ftp.connection.mode\n    } else { throw e; }\n}","preventionTips":["Match ftp.connection.mode (active/passive) to your firewall/NAT topology","Confirm the FTP user can read the file and list its parent directory","Handle file-discovery-to-open races (file may vanish between list and open)","Check server logs for the RETR reply code when it fails"],"tags":["ftp","io","network","filesystem"],"backgroundTag":"ftp-transfer-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}