To FTP

To save a GdPicture image to an FTP server, use the SaveToFTP method of the GdPictureImaging class.

Main parameters:

  • imageID — The GdPicture image identifier.
  • ImageFormat — Output format as a member of the DocumentFormat enumeration.
  • EncoderParameter — Encoding/compression parameter (depends on format).
  • Host — FTP host name.

In some cross-platform GdPicture.API (net8.0) environments, the Host parameter for SaveToFTP(...) may need to be provided as a full FTP URI (for example, ftp://example.com) rather than a bare host name (example.com). If you get an error like “The URI prefix is not recognized.”, retry with the ftp:// prefix.

  • Path — Destination path on the FTP server.
  • Login / Password — FTP credentials.
  • FTPPort — FTP port (usually 21).

SaveToFTP returns a GdPictureStatus, which should be checked.

Typical EncoderParameter values:

  • JPEG — Quality 1 to 100
  • PNG — Compression level 0 to 9
  • TIFF — Values from TiffCompression enumeration
  • JPEG2000 — Compression rate 1 to 512
  • WebP — Quality 1 to 100
  • Other formats — Usually 0

When you no longer need an image resource, release it with the ReleaseGdPictureImage method.

When transferring data to or from remote servers, you can optionally use the SetHttpTransferBufferSize method to specify the maximum package size of the transferred data. By default, the buffer size is 4096.

The following example saves a previously loaded JPG image to an FTP server:

using GdPicture14;
using System;
using GdPictureImaging gdPictureImaging = new GdPictureImaging();
int imageID = gdPictureImaging.CreateGdPictureImageFromFile(@"C:\temp\source.jpg");
if (imageID == 0)
{
Console.WriteLine($"CreateGdPictureImageFromFile failed: {gdPictureImaging.GetStat()}");
return;
}
gdPictureImaging.SetHttpTransferBufferSize(2048);
GdPictureStatus status = gdPictureImaging.SaveToFTP(
imageID,
DocumentFormat.DocumentFormatJPEG,
75,
"ftp.pspdfkit.com",
"/demo/source.jpg",
"user",
"passw0rd",
21);
if (status != GdPictureStatus.OK)
{
Console.WriteLine($"SaveToFTP failed: {status}");
}
gdPictureImaging.ReleaseGdPictureImage(imageID);