简体   繁体   English

WinSCP .NET 程序集失败,在 Session 中显示“未找到 winscp.exe 可执行文件”。在 C# 中打开 Azure function

[英]WinSCP .NET assembly fails with "The winscp.exe executable was not found" in Session.Open in C# Azure function

First I generated a simple console application to see if the generated by WinSCP works fine - and this was the case首先,我生成了一个简单的控制台应用程序,以查看 WinSCP 生成的是否正常工作——事实确实如此

Now I try to write an Azure function using WinSCP - in the same way - the same parameters - and I get an exception on Session.Open (SessionLocalException):现在我尝试使用 WinSCP 编写一个 Azure function - 以相同的方式 - 相同的参数 - 我在Session.Open (SessionLocalException) 上得到一个异常:

[Error] Executed 'WriteFile' (Failed, Id=68e2ef30-c2fb-4f5e-8444-93634a2728bb, Duration=256ms) The winscp.exe executable was not found at location of the assembly WinSC.net (D:\home\site\wwwroot\bin), nor the entry assembly Microsoft.Azure.WebJobs.Script.WebHost (D:\Program Files (x86)\SiteExtensions\Functions\3.2.0\32bit), nor in an installation path. [错误] 执行“WriteFile”(失败,Id=68e2ef30-c2fb-4f5e-8444-93634a2728bb,持续时间=256ms)在程序集 WinSC.net 的位置找不到 winscp.exe 可执行文件(D:\home\site\ wwwroot\bin),也不在入口程序集 Microsoft.Azure.WebJobs.Script.WebHost (D:\Program Files (x86)\SiteExtensions\Functions\3.2.0\32bit),也不在安装路径中。 You may use Session.ExecutablePath property to explicitly set path to winscp.exe.您可以使用 Session.ExecutablePath 属性显式设置 winscp.exe 的路径。

The winscp.exe file is not in D:\home\site\wwwroot\bin but in D:\home\site\wwwroot . winscp.exe文件不在D:\home\site\wwwroot\bin中,而是在D:\home\site\wwwroot中。 And as I'm publishing via Visual studio it is read only so I cannot just copy the file on the right location.当我通过 Visual Studio 发布时,它是只读的,所以我不能只将文件复制到正确的位置。

How can update my zip deployment so that the file gets in the right place?如何更新我的 zip 部署以使文件位于正确的位置?

My code:我的代码:

public static async Task<IActionResult> WriteFile(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req)
{
    SessionOptions sessionOptions = new SessionOptions
    {
        Protocol = Protocol.Sftp,
        HostName = "xxx",
        UserName = "xxx",
        Password = "xxx",
        SshHostKeyFingerprint = "xxx",
    };
    using (Session session = new Session())
    {
        try
        {
            session.Open(sessionOptions);
        }
        catch (SessionLocalException)
        {
            content = JsonConvert.SerializeObject(new { success = false, exception = "SessionLocalException", condition = "Error communicating with winscp.com. See the exception documentation for details." });
            return (ActionResult)new OkObjectResult($"{content}");
        }

Exception documentation for details does not help very much Could anybody help me?有关详细信息的异常文档没有多大帮助有人可以帮助我吗?


In a first time I wrote directly in Azure portal some functions to process SFTP related activities - I was new to Azure Functions but I found a way to get it handled我第一次直接在 Azure 门户中编写了一些函数来处理 SFTP 相关活动 - 我是 Azure 函数的新手,但我找到了一种方法来处理它

Now I try to write these functions in Visual Studio 2019 to publish to Azure functions现在我尝试在 Visual Studio 2019 中编写这些函数以发布到 Azure 函数

The problem is that in the C# code when I try to open a session it fails.问题是在 C# 代码中,当我尝试打开 session 时它失败了。

This exact problem is documented inWinSCP guide to transfers in Microsoft Azure Function :这个确切的问题记录在WinSCP guide to transfers in Microsoft Azure Function 中

The only problem you will face is, that for some reason, when publishing the project to an Azure storage, winscp.exe dependency is stored to the root folder of the function, instead of the bin subfolder along with other binaries (particularly the WinSC.net.dll ).您将面临的唯一问题是,出于某种原因,当将项目发布到 Azure 存储时, winscp.exe依赖项存储到 function 的根文件夹,而不是bin子文件夹以及其他二进制文件(特别是WinSC.net.dll )。

To overcome that, you need to use Session.ExecutablePath to point to the actual location of winscp.exe .为了克服这个问题,您需要使用Session.ExecutablePath指向winscp.exe的实际位置。 You can use ExecutionContext.FunctionAppDirectory to refer to the root folder of the function. To get an instance of the ExecutionContext , add new parameter to the signature of your entry method (usually Run ).您可以使用ExecutionContext.FunctionAppDirectory来引用 function 的根文件夹。要获取ExecutionContext的实例,请将新参数添加到您的入口方法(通常是Run )的签名中。

 [FunctionName("Function1")] public static void Run( [TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log, ExecutionContext context) { //... session.ExecutablePath = Path.Combine(context.FunctionAppDirectory, "winscp.exe"); }

(for full code, see the guide) (有关完整代码,请参阅指南)


After all, the exception message suggests the same:毕竟,异常消息暗示相同:

You may use Session.ExecutablePath property to explicitly set path to winscp.exe.您可以使用 Session.ExecutablePath 属性显式设置 winscp.exe 的路径。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 WinSCP 上传到 S3 .NET PowerShell 脚本失败并显示“指定目标存储桶” - Upload to S3 with WinSCP .NET PowerShell script fails with "Specify target bucket" C# Azure Function 在 URL 中对 '/' 进行切片 - C# Azure Function is slicing '/' in URL 在 python Azure Function App 中运行可执行文件 - Run an executable in python Azure Function App VS Code Azure 部署 Python Http 触发器 function 失败 - 未找到 GLIB_2.27 - VS Code Azure deployment of Python Http Trigger function fails - GLIB_2.27 not found 将我的 Azure Function 从 .net Core 3.1 升级到 .net Core 7.0。 错误“'无法加载文件或程序集'Microsoft.Extensions.Configuration.Abstraction - Upgrade my Azure Function from .net Core 3.1 to .net Core 7.0. Error "'Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstraction 将 blob 从一个 Azure 容器复制到另一个使用 ASP.NET Core 6.0 MVC 和 C# - Copy blobs from one Azure container to another using ASP.NET Core 6.0 MVC with C# 如何将数组从组件传递到 C function - How to pass array from assembly to a C function 如何在 C# 中使用 Fluent Validation 和 Azure Function 验证 JSON 对象的列表? - How to Validate a list of JSON Objects using Fluent Validation and Azure Function in C#? 在 azure function 中找不到程序集 - Assembly could not be find in azure function RabbitMqTrigger 的 ConnectionStringSetting Azure 函数 c# - ConnectionStringSetting for RabbitMqTrigger Azure Functions c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM