How to send report in PDF through FTP

FastReport .Net allows you to export reports in various formats, send them via Email, as well as via FTP. In this article, I want to focus on the transfer to the server via FTP reports. It should be noted, it is not very convenient to run each report and manually perform sending via FTP. What if a large number of reports should be sent to the server?

What are the solutions to this problem:

  1. Send all report files directly using the file manager with FTP-connections. Butbefore all reports should be exported to the desired format;
  2. Arrange export and send  report using FastReport, but do it in the application code.

Obviously, the second way will save time when you export the report in the desired format. In addition, you can completely automate this process. For example, to lay out all of the reports to a server on a schedule or one click a button.

I will show an example in which you will see the simplicity of an operation such as sending report via FTP from the application code.

Create a Windows Forms application. Place a button on the form.

Add the libraries into "using":

using FastReport;
using FastReport.Export;
using FastReport.Utils;

 Add the code for the button click handler:

 private void button1_Click(object sender, EventArgs e)
 Report report1 = new Report(); //Create new report
 FastReport.Export.Pdf.PDFExport pdf = new FastReport.Export.Pdf.PDFExport(); //Create pdf export object
 report1.Load(Environment.CurrentDirectory+"\\text.frx"); //Load report
 report1.Prepare(); //Prepare report
 FastReport.Cloud.StorageClient.Ftp.FtpStorageClient ftp = new FastReport.Cloud.StorageClient.Ftp.FtpStorageClient(); //Create ftp client
 //ftp connection settings
 ftp.Server = "";
 ftp.Username = "user";
 ftp.Password = "password";
 ftp.SaveReport(report1, pdf); //Send report

First we create an instance of the report object. Then create the export object to PDF. Then we load the report and perform its construction (Prepare). Create a client to work with FTP. You must specify all three properties: the server, user and password. Do not forget that you need to specify the path to the desired folder, otherwise the reports will be placed directly in the root. Finally, we send a report to the server. As the parameters pass the report itself and export to PDF. FastReport will make a report export and send via FTP prepared file in pdf.

Start the app, press the button and check the existence of the file on the server:

Using this simple procedure, you can send multiple reports in any of the available formats,  HTML for instance. So you can design the reports on a local computer and share them on your website.