How to send report in PDF through FTP

2017-02-27

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":

1
2
3
using FastReport;
using FastReport.Export;
using FastReport.Utils;

 Add the code for the button click handler:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
 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 = "78.47.131.251/Reports";
 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.

 

 

November 20, 2024

Localization and Language Switching in FastReport VCL

FastReport VCL supports 40 languages for interface localization and allows you to change the language on the fly through menus or code, without recompilation.
November 01, 2024

New Features of the FastReport VCL Editor

We are considering new features of the report editor: extension lines, highlighting of intersecting objects, updated report and data trees.
October 30, 2024

Using Styles When Creating Reports in FastReport VCL

The article discusses one of the new features of FastReport VCL — the use of styles and style sheets.
Fast Reports
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 66 Canal Center Plaza, Ste 505, Alexandria, VA 22314

© 1998-2024 Fast Reports Inc.