I have an Azure function running on App service plan. This Function app downloads the file from sftp and do some process/validation and then uploads to blob storage.
This was working code and I had to make some changes so that I will have to save the physical file, FileStream instead of MemoryStream. This also worked in my local environment but once deployed to Azure, I am getting FileNotFound error at the step where I download the sftp file.
Error text (edited file/class names)
System.IO.FileNotFoundException: Could not find file 'D:\home\site\wwwroot\myfile.csv'.
File name: 'D:\home\site\wwwroot\myfile.csv'
at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at MyProcessDataLoadProcess.DownLoadMyProcessFilesFromSftp.DownloadFileFromSftp(SftpClient sftp, SftpFile sftpFile, String localRootPath) in D:\a\1\s\MyProcessDataLoadProcess\DownLoadMyProcessFilesFromSftp.cs:line 173
at MyProcessDataLoadProcess.DownLoadMyProcessFilesFromSftp.Run(TimerInfo timerInfo, ILogger log, ExecutionContext context) in D:\a\1\s\MyProcessDataLoadProcess\DownLoadMyProcessFilesFromSftp.cs:line 106
I am sure this is something to do with the permissions because when I tried to create a test file using simple dir . > test.txt from platform features' command line tool, I am getting the "system could not find file specefied error".
I am sure this has to do something with settings that will allow writing to the local disc because I did a POC using different subsciption where I have full permissions. I am not sure if this can be configured somewhere in app settings or need to give permissions at storage level or subscription level permissions.
Update:
For now, I found a workaround to use a temporary folder by using Path.GetTempPath(). However, I am bit puzzled what is that restriction stopping me to create the file in the root folder.