问题
I've deployed a website into Azure and i want to access programaticaly this path : "D:\home\site\app" from a c# desktop application and delete all files and upload new ones programatically.
i have searched and found many ways but all are for AzureStorage
or using Kudu consol
or FTP
while what i realy want is to access the local storage where the website is deployed programatiacally, and make some edits on files programatically.
回答1:
Sure thing, the Site Control Manager (Kudu) has an API for that, the VFS API: https://github.com/projectkudu/kudu/wiki/REST-API#vfs
You can use either of these for authentication:
- A
Bearer
token that you obtain from the STS (reference implementation in ARMClient) - Site-level credentials (the long ugly ones under your Web App → Properties)
- Git/FTP credentials (subscription level)
Sample usage (using site-level credentials):
# Line breaks brutally used to improve readability
# /api/vfs/ is d:\home
# Append path as necessary, i.e. /api/vfs/site/app
$ curl -k https://$are-we-eating-too-much-garlic-as-a-people:6sujXXX
XXXXXXq7Zc@are-we-eating-too-much-garlic-as-a-people.scm.azurewebsites.net
/api/vfs/site/wwwroot/ill-grab-this-file-over-vfs-api.txt
There, i did it.
I'm assuming here that you want to do all that from the outside world - since you don't clearly state otherwise.
回答2:
Well, in my azure code. my task was to save a excel file and upload its contents to SQL server. I used this plain and simple to access home site.
string fileToSave = string.Format("{0}\\{1}", HostingEnvironment.MapPath(@"~\Temp"), FileUpload.FileName);
if (!Directory.Exists(HostingEnvironment.MapPath(@"~\Temp")))
Directory.CreateDirectory(HostingEnvironment.MapPath(@"~\Temp"));
FileUpload.PostedFile.SaveAs(fileToSave);
you could use something like this to delete and save a new file or other I/O operations.
来源:https://stackoverflow.com/questions/41264564/delete-and-upload-files-into-azure-webapp-local-storage-programatically