Saving to FTP Server
Products: FastReport Cloud, FastReport Corporate Server, FastReport Publisher
In this article, we will consider the method of sending a report to an FTP server. Instructions on how to work with tasks are described in the General Information section.
Getting Started
You will need the following tools and capabilities:
Knowledge of using API key in Service solutions.
This article will skip additional information on authentication and authorization.
C# code editor or text editor, such as Visual Studio Code.
Report template.
It can be prepared using the free FastReport Community Designer program.
Active subscription to one of the following products: FastReport Cloud, FastReport Corporate Server, or FastReport Publisher.
Internet access.
Configured and accessible FTP server.
Note! This guide assumes that you already know how to develop your application in the C# programming language.
Note! The points above describe the recommended tools.
Note! This guide assumes that you have experience configuring and setting up an FTP server to accept files from external sources.
Creating a Task
Let's consider creating a template sending task to FTP server:
// Object initialization
CreateFTPUploadTaskVM ftpUploadTaskVM = new CreateFTPUploadTaskVM
{
Name = "FTP Sending Task",
InputFile = new InputFileVM
{
EntityId = "{template identifier}",
Type = FileKind.Template
},
FtpHost = "{FTP server address}",
FtpPort = 21,
FtpUsername = "{FTP server username}",
FtpPassword = "{password}",
UseSFTP = false,
DestinationFolder = "{/path_to_folder/}",
Archive = false,
ArchiveName = "Archive Name",
SubscriptionId = "{workspace identifier}"
};
// Creating a task
TaskBaseVM ftpUploadTask = await tasksClient.CreateTaskAsync(ftpUploadTaskVM);
// Run task by identifier
await tasksClient.RunTaskByIdAsync(ftpUploadTask.Id);
Real object identifiers should be entered in the EntityId and SubscriptionId fields. Otherwise, the task will be aborted with an error.
Executing Task from Request Body
// Run task from request body
await tasksClient.RunTaskAsync(new RunFTPUploadTaskVM
{
InputFile = new RunInputFileVM
{
EntityId = "{template identifier}",
Type = FileKind.Template
},
FtpHost = "{FTP server address}",
FtpPort = 21,
FtpUsername = "{FTP server username}",
FtpPassword = "{password}",
UseSFTP = false,
DestinationFolder = "{/path_to_folder/}",
Archive = false,
ArchiveName = "Archived Template",
SubscriptionId = "{workspace identifier}"
});
Note! In this case, the FTP sending will be performed directly by this request and the task will not be saved in the database.
Updating Task by Identifier
await tasksClient.UpdateTaskAsync("{old task identifier}", new UpdateFTPUploadTaskVM()
{
InputFile = new RunInputFileVM
{
EntityId = "{updated template identifier}",
Type = FileKind.Template
},
FtpHost = "{Updated FTP server address}",
FtpPort = 21,
FtpUsername = "{updated FTP server username}",
FtpPassword = "{updated password}",
UseSFTP = false,
DestinationFolder = "/updated_path_to_folder",
Archive = false,
ArchiveName = "Updated Archive Name"
});