{"record":{"id":"b8895638c2998c8b","repo":"apache/seatunnel","slug":"file-already-exists-file","errorCode":null,"errorMessage":"File already exists: ${file}","messagePattern":"File already exists: (.+?)","errorType":"exception","errorClass":"FileAlreadyExistsException","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":361,"sourceCode":"            short replication,\n            long blockSize,\n            Progressable progress)\n            throws IOException {\n        final FTPClient client = connect();\n        Path workDir = new Path(client.printWorkingDirectory());\n        Path absolute = makeAbsolute(workDir, file);\n        FileStatus status;\n        try {\n            status = getFileStatus(client, file);\n        } catch (FileNotFoundException fnfe) {\n            status = null;\n        }\n        if (status != null) {\n            if (overwrite && !status.isDirectory()) {\n                delete(client, file, false);\n            } else {\n                disconnect(client);\n                throw new FileAlreadyExistsException(\"File already exists: \" + file);\n            }\n        }\n\n        Path parent = absolute.getParent();\n        if (parent == null || !mkdirs(client, parent, FsPermission.getDirDefault())) {\n            parent = (parent == null) ? new Path(\"/\") : parent;\n            disconnect(client);\n            throw new IOException(\"create(): Mkdirs failed to create: \" + parent);\n        }\n        client.allocate(bufferSize);\n        // Change to parent directory on the server. Only then can we write to the\n        // file on the server by opening up an OutputStream. As a side effect the\n        // working directory on the server is changed to the parent directory of the\n        // file. The FTP client connection is closed when close() is called on the\n        // FSDataOutputStream.\n        client.changeWorkingDirectory(parent.toUri().getPath());\n        FSDataOutputStream fos =\n                new FSDataOutputStream(client.storeFileStream(file.getName()), statistics) {","sourceCodeStart":343,"sourceCodeEnd":379,"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#L343-L379","documentation":"SeaTunnelFTPFileSystem.create() checks for an existing file at the target path. If the file exists and overwrite is false, it disconnects and throws org.apache.hadoop.fs.FileAlreadyExistsException('File already exists: <file>'). When overwrite is true the existing file is deleted instead.","triggerScenarios":"Calling create(file, overwrite=false) (or the default create(Path) overload) where getFileStatus() finds an existing non-directory entry at the FTP server path.","commonSituations":"Re-running a job writing to a fixed output filename without overwrite; concurrent writers claiming the same path; leftover output from a previous failed run.","solutions":["Set overwrite=true in create(), or enable the overwrite option in the SeaTunnel sink config if replacing is intended","Delete the existing file on the FTP server or write to a unique filename (timestamp/UUID suffix)","Ensure only one job writes to the same path at a time"],"exampleFix":"// before\nfs.create(new Path(\"ftp://host/out/result.csv\")); // overwrite=false default\n// after\nfs.create(new Path(\"ftp://host/out/result.csv\"), true); // explicit overwrite","handlingStrategy":"validation","validationCode":"// Java\nFileSystem fs = path.getFileSystem(conf);\nif (fs.exists(path) && !overwrite) {\n    throw new FileAlreadyExistsException(\"Refusing to write existing file: \" + path);\n}","typeGuard":null,"tryCatchPattern":"try {\n    return fs.create(path, overwrite);\n} catch (FileAlreadyExistsException e) {\n    // decide: fail the job, or pick a new unique path\n    Path unique = new Path(path.getParent(), System.currentTimeMillis() + \"_\" + path.getName());\n    return fs.create(unique, false);\n}","preventionTips":["Pass overwrite=true explicitly when replacement is intended","Generate unique output names (timestamp/partition suffix) for idempotent reruns","Clean up stale outputs from failed runs before resubmitting","Ensure a single writer owns each output path"],"tags":["ftp","filesystem","file","conflict"],"backgroundTag":"file-already-exists","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"}