从SFTP文件夹中删除文件。

huangapple go评论78阅读模式
英文:

Delete files from the SFTP folder

问题

我有一个存档文件夹,我想每天触发工作流程并检查是否有一些文件超过3个月了。
我尝试这样做:运行一个触发器,列出文件夹中的文件,进入循环并检查文件是否超过3个月,然后执行删除操作。是否有更好/更快的方法?我有点犹豫,因为我认为遍历所有文件可能不是最快的选项(我可能有数千个文件)。

英文:

I have an archive folder and i want to trigger workflow every day and check if there are some files which are older than 3 month.
I tried to do it like this: run a trigger, list files in the folder, go into a for each and check if file is older than 3 month and just delete action. Are there some better/faster ways to do it? I am in doubt a bit because i don't think going thru the all files will be the faster options (i could have thousands files).

答案1

得分: 0

如果您正在寻找一种更有效的方法来删除位于SFTP路径中的归档文件夹中已经超过3个月的文件,您可以考虑使用Azure Functions与Azure Logic App结合使用。Azure Functions提供了更多的灵活性和控制权,可以优化性能并高效处理大量文件。

以下是使用Azure Functions和Azure Logic App的备选方法:

  1. 创建Azure Function:使用您喜欢的编程语言(如C#,Python或JavaScript)创建一个新的Azure Function。此函数将负责删除归档文件夹中的文件。

  2. 配置Azure Function:在Azure Function内部实现逻辑,以连接到SFTP服务器,列出归档文件夹中的文件,并删除符合条件的文件(即超过3个月的文件)。您可以使用已有的SFTP库或模块来与SFTP服务器进行交互,根据您选择的编程语言。

  3. 发布Azure Function:将Azure Function发布到Azure,并确保可以通过HTTP端点访问它。

  4. 修改Logic App:在Logic App中,将“删除文件”操作替换为“HTTP”操作。配置HTTP操作,使其向在步骤3中发布的Azure Function端点发出请求。在HTTP请求中传递任何必需的参数,如SFTP服务器详细信息和归档文件夹路径。

  5. 保存并测试:保存Logic App,并通过手动运行或等待定期触发来进行测试。Logic App将触发Azure Function,以删除归档文件夹中已经超过3个月的文件。

通过利用Azure Functions,您可以利用更强大的脚本功能,并根据特定需求微调删除过程。这种方法允许在处理大量文件时实现更好的可扩展性和性能,因为Azure Functions可以处理并行处理并优化资源分配。

英文:

If you're looking for a more efficient way to delete files from an archive folder in an SFTP path that are older than 3 months, you can consider using Azure Functions in conjunction with Azure Logic App. Azure Functions provide more flexibility and control over the deletion process, allowing you to optimize performance and handle large numbers of files efficiently.

Here's an alternative approach using Azure Functions and Azure Logic App:

  1. Create an Azure Function: Create a new Azure Function using your preferred language (such as C#, Python, or JavaScript). The function will handle the deletion of files from the archive folder.

  2. Configure the Azure Function: Implement the logic within the Azure Function to connect to the SFTP server, list the files in the archive folder, and delete files that meet the criteria (i.e., older than 3 months). You can use existing SFTP libraries or modules for your chosen programming language to interact with the SFTP server.

  3. Publish the Azure Function: Publish the Azure Function to Azure and ensure it is accessible via an HTTP endpoint.

  4. Modify the Logic App: In the Logic App, replace the "Delete file" action with an "HTTP" action. Configure the HTTP action to make a request to the Azure Function endpoint you published in step 3. Pass any required parameters, such as the SFTP server details and the archive folder path, as part of the HTTP request.

  5. Save and Test: Save the Logic App and test it by running it manually or waiting for the scheduled recurrence. The Logic App will trigger the Azure Function to delete files from the archive folder that are older than 3 months.

By leveraging Azure Functions, you can utilize more powerful scripting capabilities and fine-tune the deletion process based on your specific requirements. This approach allows for better scalability and performance when dealing with a large number of files, as Azure Functions can handle parallel processing and optimize resource allocation.

huangapple
  • 本文由 发表于 2023年6月5日 20:18:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76406336.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定