Symptom:

The distribution agent failed to create temporary files in ‘C:\Program Files\Microsoft SQL Server\130\COM’ directory
The distribution agent failed to create temporary files in 'C:\Program Files\Microsoft SQL Server\130\COM' directory. System returned errorcode 5. (Source: MSSQL_REPL, Error number: MSSQL_REPL21100)
Get help: http://help/MSSQL_REPL21100

Resolution:
– Add ‘NT Service\SQLSERVERAGENT’ account FULL permissions into the ‘C:\Program Files\Microsoft SQL Server\[NNN]\COM’ directory (e.g. ‘C:\Program Files\Microsoft SQL Server\130\COM’)
– Assuming that the default account has been used as the run-as account for the SQL Server Agent service.
– Assuming the referenced account above is assigned to the replication job.
– If the Distribution Agent is invoked from a command line, one must grant write permissions to the COM folder for the account that is used to run the Distribution Agent.