1
votes

I have an Azure app service that host a wordpress site. I want to write a console application that will copy files from the website (file storage) and paste them in a deployment slot. All of the online resources talk about "access keys" for connection to the file storage, but I do not see anything like this in the app service portal. Can I use deployment credentials or web deploy credentials to access these files?

2
Well, if FTP would be okay for you, those credentials work directly as FTP credentials, giving you access to the filesystem.juunas
According to your description, I couldn’t understand clearly about the website(file storage).Do you mean you store the file inside an file storage share (azure storage service) or just the application file system’s shared path?How you store the file, upload it by your application or any other way?This two thing will decide which webjobtigger you will use. The access key is used to access the azure storage service, if you want to access the filesystem in your application service, you could use the ftp credentials.Brando Zhang
I"m not using file storage just the file system. I want to create a webjob that will access the files in the file system and copy files to a slot.Jim Kiely

2 Answers

4
votes

According to your description, I suggest you could use webjob’s file tigger to achieve your requirement.

Link:webjob-extension

You could use the file tigger to watch the file changes in your system file path, you could find the deployment slot’s ftp credential, then use it to upload the file form production folder to the deployment slot by webjob’s extension package.

More details, you could refer to follow image and codes:

1.Find the ftp credential and set password

enter image description here

Set username and password

enter image description here

2..Install the Microsoft.Azure.WebJobs.Extensions from nugget package manager and write the webjob method.

Codes like below:

Note: The default file path is D:/home/data, if your file inside your website folder, you need change its path as below.

   static void Main()
    {
        var config = new JobHostConfiguration();
        FilesConfiguration filesConfig = new FilesConfiguration();
        string home = Environment.GetEnvironmentVariable("HOME");
        if (!string.IsNullOrEmpty(home))
        {
            filesConfig.RootPath = Path.Combine(home, "site");
        }
        config.UseFiles(filesConfig);
        var host = new JobHost(config);
        // The following code ensures that the WebJob will be running continuously
        host.RunAndBlock();
    }

Function:

public static void ImportFile(
                [FileTrigger(@"wwwroot\doc\{name}", "*.*", WatcherChangeTypes.Created | WatcherChangeTypes.Changed)] Stream file,
            FileSystemEventArgs fileTrigger,
            TextWriter log)
        {
            log.WriteLine(string.Format("Processed input file '{0}'!", fileTrigger.Name));
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(string.Format("ftp://yourftpurl.ftp.azurewebsites.windows.net/site/wwwroot/doc/{0}", fileTrigger.Name));
            request.Method = WebRequestMethods.Ftp.UploadFile;
            request.Credentials = new NetworkCredential(@"username", "password");

            Stream requestStream = request.GetRequestStream();
            file.CopyTo(requestStream);
            requestStream.Close();
            FtpWebResponse response = (FtpWebResponse)request.GetResponse();
            log.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
            response.Close();
        }

Result:

If you add file to the production’s doc folder, the web job will copy it to deploymeny_solt’s doc folder.

enter image description here

1
votes

You could use the "Azure Site Replicator" extension. A slot is like another azure app service, so it should replicate between slots just fine.

In your deployment slot that you want everything copied to, download the Publish Settings from the overview tab by clicking "Get Publish Profile"

In your app service production slot go to Extensions and add the Site Replicator extension. Then after it is installed, click it and click 'Browse.' That will open a new window with the configuration options.

In the configuration window, upload the Publish Settings file.