question

BillBell-6414 avatar image
0 Votes"
BillBell-6414 asked MayankBargali-MSFT commented

Newbie - Getting WinSCP Working

I have an Azure function app (C#) and one of the functions queries an SQL DB, creates a JSON file and FTPs it to a website. I'm using WinSCP. It works locally. The .csproj contains reference to package.

<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="4.0.4" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.13" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
<PackageReference Include="WinSCP" Version="5.19.0" />
</ItemGroup>

I'm using VS 2019. I use VS to publish app as a package file. When I do remote debugging I get this error.

The winscp.exe executable was not found at location of the assembly WinSCPnet (C:\home\site\wwwroot\bin), nor the entry assembly Microsoft.Azure.WebJobs.Script.WebHost (C:\Program Files (x86)\SiteExtensions\Functions\3.0.15961\32bit), nor in an installation path. You may use Session.ExecutablePath property to explicitly set path to winscp.exe.

How do I find where it is installed? How do I fix?

azure-functions
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

BillBell-6414 avatar image
0 Votes"
BillBell-6414 answered MayankBargali-MSFT commented

Figured it out. Used console to figure out WinSCP.exe is located at C:\\home\site\wwwroot\WinSCP.exe . Used session ExecutablePath to set when running in Azure .

        SessionOptions sessionOptions = new SessionOptions()
         {
             Protocol = Protocol.Ftp,
             HostName = GetEnvironmentVariable("WinSCP-Site", EnvironmentVariableTarget.Process),
             UserName = GetEnvironmentVariable("WinSCP-Username", EnvironmentVariableTarget.Process),
             Password = GetEnvironmentVariable("WinSCP-Password", EnvironmentVariableTarget.Process)
         };

         Session session;

         using (session = new Session())
         {
             string runLoc = GetEnvironmentVariable("RunLocation", EnvironmentVariableTarget.Process);
             if (runLoc == "Azure")
             {
                 session.ExecutablePath = GetEnvironmentVariable("WinSCP-Executable", EnvironmentVariableTarget.Process);
             }
             session.Open(sessionOptions);

             TransferOptions transferOptions = new TransferOptions();
             transferOptions.TransferMode = TransferMode.Ascii;


             TransferOperationResult transferResult = null;

             transferResult = session.PutFiles(fn, GetEnvironmentVariable("TombstonePath", EnvironmentVariableTarget.Process), false, transferOptions);
             transferResult.Check();

              if (eMsg == "")
             {
                 eMsg = $"Successfully ran function Tombstone at {DateTime.Now.ToString("MM-dd-yyyy HH:mm:ss")}";
             }
         }


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@BillBell-6414 Thank you for sharing your solution with the community. We appreciate your contribution.

0 Votes 0 ·