Access to the path denied Error in SysOperation batch job in D365

Hi All,

I am trying to access a private key file which is placed in the local folder to get connected to sftp. but I am getting the below error when running the controller class through sys operation batch. but the process is successfully getting completed when done manually. Please suggest a solution to fix this issue. The error is pasted below:

System.UnauthorizedAccessException: Access to the path ‘C:\Temp\Dixf\OpenSSh.ppk’ is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode,
FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize,
FileOptions options, SECURITY_ATTRIBUTES secAttrs,
String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream…ctor(String path, FileMode mode,
FileAccess access, FileShare share) at System.IO.File.Open(String path, FileMode mode,
FileAccess access, FileShare share) at Renci.SshNet.PrivateKeyFile…ctor
(String fileName, String passPhrase) at Renci.SshNet.PrivateKeyFile…ctor(String fileName) at
Dynamics.AX.Application.SFTPFileOperations.SFTPConnect() in xppSource://Source/ Interface Model\AxClassSFTPFileOperations.xpp:line 30 at Dynamics.AX.Application.SFTPFileOperations.SFTPConnect() at Dynamics.AX.Application.AP_FileProcess.run()
in xppSource://Source/Interface Model\AxClassAP_FileProcess.xpp:line 112 at Dynamics.AX.Application.AP_FileProcess.run()
at Dynamics.AX.Application.APFileProcessController.`run() in
xppSource://Source/Interface Model\AxClass_APFileProcessController.xpp:line 21 at
Dynamics.AX.Application.APFileProcessController.run() at
Dynamics.AX.Application.BatchRun.runJobStaticCodeFromBuffer(Batch buffer)
in xppSource://Source/ApplicationPlatform\AxClass_BatchRun.xpp:line 848 at
Dynamics.AX.Application.BatchRun.runJobStaticFromBuffer(Batch buffer)
in xppSource://Source/ApplicationPlatform\AxClass_BatchRun.xpp:line 770 at
Microsoft.Dynamics.AX.Batch.Batch.ExecuteOneBatchJobTask(BatchTaskInfoWrapper taskInfo

Thanks in Advance,

Gopinath

It seems that the user account used to run batch.exe doesn’t have permissions to access the file.

But how do you intend to use such a design in production? You don’t control the machines in cloud and there be many AOS servers, each of them would have to have a local copy of the file at the same path. It doesn’t look like feasible architecture to me.

Hi Martin,

Can you suggest me a solution to solve this issue please.

Thanks in Advance,

Gopinath

You should store the file in a location shared by all application servers. I suggests Azure Key Vault, because it’s safer and gives you more control than if you use a general file storage.

If you insist of using the file directly, you can put it into Azure Blob Storage or to database.