I have an FTP source that adds daily file and I need to copy the files on daily basis from FTP to blob storage using FluentFTP library in azure function
(我有一个添加每日文件的FTP源,我需要每天在Azure函数中使用FluentFTP库将文件从FTP复制到Blob存储)
I am using C# in Azure function, and I did all the coding part but missing to download the file from FTP to copy it directly to the blob destination.
(我在Azure函数中使用C#,我做了所有编码部分,但是缺少从FTP下载文件以将其直接复制到Blob目标的操作。)
//#r "FluentFTP"
#r "Newtonsoft.Json"
#r "System.Data"
#r "Microsoft.WindowsAzure.Storage"
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Globalization;
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using FluentFTP;
public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
string blobConnectionString = "ConnectionString";
// Gestione BLOB Storage
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(blobConnectionString);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("out");
using (FtpClient conn = new FtpClient())
{
conn.Host = "ftp server";
conn.Credentials = new NetworkCredential("username", "pass");
// get a list of files and directories in the "/OUT" folder
foreach (FtpListItem item in conn.GetListing("/OUT"))
{
// if this is a file and ends with CSV
if (
item.Type == FtpFileSystemObjectType.File
&&
item.FullName.ToLower().EndsWith(".csv")
)
{
string yyyy = item.FullName.Substring(10,4);
string mm = item.FullName.Substring(14,2);
string dd = item.FullName.Substring(16,2);
var fileName = "out/brt/" + yyyy + "/"+ mm + "/"+ dd + "/" + item.Name;
CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName);
// download the file
conn.DownloadFile( blockBlob , item.FullName);
}
}
return new OkObjectResult($"Hello");
}
}
If I can use a blob container as a destination for the FluentFTP function then it would be the best, but this way I am getting the error that this blob block that I am using is not an a destination
(如果我可以将blob容器用作FluentFTP函数的目标,那将是最好的选择,但是这样我会收到以下错误消息:我正在使用的blob块不是目标)
This is the error that I am getting
(这是我得到的错误)
cannot convert from 'Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob' to 'string'
(无法从“ Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob”转换为“字符串”)
I don't know if there is another way to download the file locally so I can upload it to the blob instead of using this client.DownloadFile
function.
(我不知道是否还有另一种本地下载文件的方法,因此我可以将其上传到Blob,而不是使用此client.DownloadFile
函数。)
ask by Ahmed Essam translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…