Newbie - Getting WinSCP Working

Bill Bell 101 Reputation points
2021-06-18T14:01:37.007+00:00

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
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,215 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bill Bell 101 Reputation points
    2021-06-18T22:58:49.72+00:00

    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")}";
                }
            }
    

0 additional answers

Sort by: Most helpful