Send File From Blob Storage to FTP Server

55 Views Asked by At

I am using DataFactory in my work.

I'm considering transferring files from Blob storage to an on-premises FTP server, but is there a good way to implement it?

When I looked into it, I found Logic Apps, Azure Functions, and Custom Activities, but I wonder if there is an easier way to implement it...

1

There are 1 best solutions below

0
Bhavani On

According to this, we cannot write a file into FTP server from blob storage using ADF directly. You can make use of Azure Functions to copy data from Azure blob storage to an on-premises FTP server.

  • Get the Azure file as a Stream [Handled by Azure Functions for you]
  • Use WebClient to upload the Stream

You can use the code below:

public void UploadStreamToFtp(Stream file, string targetFilePath)
{
    using (MemoryStream ms = new MemoryStream())
    {
        // As MemoryStream already handles ToArray(), copy the Stream to the MemoryStream
        file.CopyTo(ms);

        using (WebClient client = new WebClient())
        {
            // Use login credentials if required
            client.Credentials = new NetworkCredential("username", "password");

            // Upload the stream as Data with the STOR method call
            // targetFilePath is a fully qualified filepath on the FTP, e.g. ftp://targetserver/directory/filename.ext
            client.UploadData(targetFilePath, WebRequestMethods.Ftp.UploadFile, ms.ToArray());
        }
    }
}

For more information, you can refer to this SO answer.