files-community/Files · error · IOException

Failed to create file {remotePath}.

Error message

Failed to create file {remotePath}.

What it means

Thrown by the WinRT-facing FtpStorageFolder.CreateFileAsync (Files.App/Utils) when UploadStream returns a status that is neither Success nor Skipped - i.e. FtpStatus.Failed - after the GenerateUniqueName retry loop and the FailIfExists branch have both been ruled out. The upload could not complete for a server-side reason.

Source

Thrown at src/Files.App/Utils/Storage/StorageItems/FtpStorageFolder.cs:228

				}
				while (result is FtpStatus.Skipped && ++attempt < 1024 && options == CreationCollisionOption.GenerateUniqueName);

				if (result is FtpStatus.Success)
				{
					var file = new FtpStorageFile(new StorageFileWithPath(null, $"{Path}/{finalName}"));
					((IPasswordProtectedItem)file).CopyFrom(this);
					return file;
				}

				if (result is FtpStatus.Skipped)
				{
					if (options is CreationCollisionOption.FailIfExists)
						throw new FileAlreadyExistsException(desiredName);

					return null;
				}

				throw new IOException($"Failed to create file {remotePath}.");
			}, ((IPasswordProtectedItem)this).RetryWithCredentialsAsync));
		}

		public override IAsyncOperation<BaseStorageFolder> CreateFolderAsync(string desiredName)
			=> CreateFolderAsync(desiredName, CreationCollisionOption.FailIfExists);
		public override IAsyncOperation<BaseStorageFolder> CreateFolderAsync(string desiredName, CreationCollisionOption options)
		{
			return AsyncInfo.Run((cancellationToken) => SafetyExtensions.Wrap<BaseStorageFolder>(async () =>
			{
				using var ftpClient = GetFtpClient();
				if (!await ftpClient.EnsureConnectedAsync())
				{
					throw new IOException($"Failed to connect to FTP server.");
				}

				string fileName = $"{FtpPath}/{desiredName}";
				if (await ftpClient.DirectoryExists(fileName))
				{

View on GitHub (pinned to 68c68a58d4)

Solutions

  1. Read ftpClient.LastReply for the underlying 4xx/5xx reply and report the specific code.
  2. Confirm the target folder exists and the account has write permission.
  3. Retry with backoff on transient failures (network drops are common).
  4. If quota is the cause, free space on the server or use a different account.
  5. Wrap in try/catch and present a user-readable failure with the remote path.

Example fix

// before
throw new IOException($"Failed to create file {remotePath}.");

// after
var reply = ftpClient.LastReply;
throw new IOException($"Failed to create file {remotePath}: {(int)reply?.Code} {reply?.Message}");
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify write permission and parent existence before the upload.
if (!await ftpClient.DirectoryExists(FtpPath, ct))
    throw new IOException("Parent folder missing; cannot create file.");

Try / catch

try { return await folder.CreateFileAsync(name, options); }
catch (IOException ex) when (ex.Message.Contains("Failed to create file"))
{ var reply = ftpClient.LastReply; /* log and report specific code */ throw; }

Prevention

When it happens

Trigger: UploadStream returning FtpStatus.Failed during CreateFileAsync after the unique-name loop exhausted (or collision option was OpenIfExists/ReplaceExisting). Permission denied on the folder, missing parent directory, quota exceeded, or a dropped data connection.

Common situations: Read-only FTP target; nested path whose parent was never created; quota hit; unstable network breaking PASV data channel mid-upload; antivirus quarantining the uploaded file on the server.

Related errors


AI-assisted analysis of files-community/Files@68c68a58d4 (2026-08-13). Data as JSON: /api/errors/ee008913c60b29ec. Report an issue: GitHub.