web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Download pictures to FTP server from BC Cloud

(0) ShareShare
ReportReport
Posted on by 574

I am working on a BC Cloud.

I need to automate a download of the item pictures to an FTP Server (or some public folder) in order to let other external system to get those pictures.

The process should be unassisted, I mean, we do not expect any person to execute task, downloading, copying files, using Filezilla or this kind of tasks.

How would you do this? Azure storage? Azure app services?

I have the same question (0)
  • Suggested answer
    Mohana Yadav Profile Picture
    60,993 Super User 2025 Season 2 on at

    we can store the files in Azure storage containers and automate the process to import from Azure storage containers to BC.

    Please refer below blog as reference.

    https://dynamics.is/?p=3352

  • Suggested answer
    THE Italian Profile Picture
    on at

    you could also check this reference

    demiliani.com/.../

  • AntonioTorre Profile Picture
    574 on at

    Thank you Dulio, is there any github or repo where I can pick up the code. I have copy+paste the code in that post and I get an error when connecting to FTP. I have also purchased your book with Stefano Demiliani but I cant make it work.

    Here are the details of the error I get with the code in that post:

    I am trying to upload a file into SFTP using Renci.SshNet within an Azure Function (find at the bottom).

    I get a error when this line is executed: client.Connect();

    Error is:

    "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond."

    My user/password/ip/port are correct (I have checked it with Filezilla) Do you know what could be happening?

    private static async Task<string> UploadFileToSFTP(Uri uri, string sourceFileName, ILogger log )
    {
        string storageAccountContainer = "csvfiles4magento";
        string storageConnectionString = BLOBStorageConnectionString;
        string sourceFileAbsolutePath = uri.ToString();
        //SFTP Parameters (read it from configurations or Azure KeyVault)
        string sftpAddress = "address";
        string sftpPort = "port";
        string sftpUsername = "username";
        string sftpPassword = "password";
        string sftpPath = "var";
                string targetFileName = sourceFileName;
                var memoryStream = new MemoryStream();
    
                CloudStorageAccount storageAccount;
                if (CloudStorageAccount.TryParse(storageConnectionString, out storageAccount))
                {
                    CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
                    CloudBlobContainer cloudBlobContainer = 
                                       cloudBlobClient.GetContainerReference(storageAccountContainer);
    
                    CloudBlockBlob cloudBlockBlobToTransfer = 
                    cloudBlobContainer.GetBlockBlobReference(new CloudBlockBlob(uri).Name);
                    await cloudBlockBlobToTransfer.DownloadToStreamAsync(memoryStream);
                }
    
                var methods = new List<AuthenticationMethod>();
                methods.Add(new PasswordAuthenticationMethod(sftpUsername, sftpPassword));
    
                //Connects to the SFTP Server and uploads the file 
                Renci.SshNet.ConnectionInfo con = new Renci.SshNet.ConnectionInfo(sftpAddress, sftpPort, new PasswordAuthenticationMethod(sftpUsername, sftpPassword));
                using (var client = new SftpClient(con))
                {
    
                    client.Connect();
    
                    client.UploadFile(memoryStream, $"/{sftpPath}/{targetFileName}");
                    client.Disconnect();
                    return targetFileName;
                }
    }]
    

    Thank you

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    As the name says, the Renci SSH.NET library is an SSH FTP librar (SFTP), so different from standard FTP..

    You cannot use the Renci SSH.NET for the simple FTP protocol, I suggest to use another library (but code sample is the same) or simply something like:

    using (var client = new WebClient())

    {

       client.Credentials = new NetworkCredential(ftpUsername, ftpPassword);

       client.UploadFile("ftp://host/path.zip", WebRequestMethods.Ftp.UploadFile, localFile);

    }

  • AntonioTorre Profile Picture
    574 on at

    Yes, you are right, the title of my post says FTP, but it should say SFTP, which in fact, is the type of protocol I am trying to reach. I still get same error.

  • AntonioTorre Profile Picture
    574 on at

    Duilio/Stefano, do you know if the code of that post is available in some repo or github? I must be doing something wrong as I cant make it work

  • Suggested answer
    THE Italian Profile Picture
    on at

    No idea. You could ask the author of the post in the post itself or send an email to the book author.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,229

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,867 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,153 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans