How access VM file share from Azure Function app

Nuwan Wickramanayaka 81 Reputation points
2022-11-04T19:31:30.813+00:00

Hi all

I am having VM file share and needs to read files by using Azure function app. All are in same network (app service ) .

I am trying to access file using path \xxxx.xxxx.com\pdf_directory\sample.pdf" and trying to the get the file size

FileInfo fileInfo = new FileInfo(filename);
fileLength = fileInfo.Length;

It gives error "unauthorized access when accessing file". Still I couldn't find any reason for that. Let me know how to resolve this issue ?

Thanks
Nuwan

Azure Files
Azure Files
An Azure service that offers file shares in the cloud.
1,169 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,298 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,436 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Carlos Solís Salazar 16,611 Reputation points
    2022-11-04T21:49:02.11+00:00

    Hi @Nuwan Wickramanayaka

    Thank you for asking this question on the **Microsoft Q&A Platform. **

    Assuming that the Azure Function is in the same virtual network as the VM (If not check this documentation https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-vnet)

    The reason is that the Function App does not have permission to access the VM,

    A way to authenticate is via Automation Account https://serverfault.com/questions/893506/how-to-log-in-to-azure-vm-automatically-from-azure-function

    Depending on the language that you are using in your Function you can authenticate in your VM in diverse ways

    Hope this helps!

    ----------

    Accept Answer and Upvote, if any of the above helped, this thread can help others in the community looking for remediation for similar issues.
    NOTE: To answer you as quickly as possible, please mention me in your reply.


  2. Roderick Bant 2,046 Reputation points
    2022-11-10T13:11:22.313+00:00

    Hi @Nuwan Wickramanayaka

    your question seems to have elements similar to this question on accessing on premise file shares from an Azure Function App. @ajkuma 's answer there indicates that the Sandbox environment restricts outgoing SMB ports.

    In a similar question and answer @ChaitanyaNaykodi-MSFT suggests using a logic app to handle interactions with the file share and connecting the logic app to the function app. The extra logic app may not be the most elegant solution, but it will be an effective and supported means to get the results you need .

    0 comments No comments