2

I am writing an Azure function that uses WinSCP library to download files using SFTP and upload the files on blob storage. This library doesn't allow to get files as a Stream. Only option is to download them locally. My code also uses a private key file. So i have 2 questions.

  1. sessionOptions.SshPrivateKeyPath = Path.GetFullPath("privateKey2.ppk"); is working locally. I have added this file in solution with option "copy to output" and it works. But will it work when Azure function is deployed?
    enter image description here

  2. While getting the files I need to specify local path where the files will be downloaded.

    var transferResult = session.GetFiles(
        file.FullName, Path.GetTempPath() + @"SomeFolder\" + file.Name, false,
        transferOptions); 
    

    The second parameter is the local path.

    What should I use in place of Path.GetTempPath() that will work when Azure function is deployed?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Raas Masood
  • 1,475
  • 3
  • 23
  • 61

1 Answers1

1

For the private key, just deploy it along with your function project. You can simply add it to your VS project.

See also Including a file when I publish my Azure function in Visual Studio.


For the download: The latest version of WinSCP already supports streaming the files. Use the Session.GetFile method.

To answer your question about the temporary location, see:

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992