PowerTCP FTP for .NET
Encoding Property (Ftp)
Example 



Specifies the character encoding to be used by the component.
Syntax
Public Overrides Property Encoding As Encoding
Dim instance As Ftp
Dim value As Encoding
 
instance.Encoding = value
 
value = instance.Encoding
public override Encoding Encoding {get; set;}
public:
property Encoding^ Encoding {
   Encoding^ get() override;
   void set (    Encoding^ value) override;
}
Remarks
When this property is set the component will use the specified encoding to encode and decode data on the underlying socket.
Example
This example demonstrates sending FTP commands and processing the response.
public void InitConnection(object state)
{
    //Connect to the FTP server.
    ftp1.Connect();

    //Use UTF8 if available. 
    //NOTE: Some servers require the user to be authenticated before UTF8 support can be enabled,
    //if that is true then the following line must be called after the call to ftp1.Authenticate();
    UseUTF8();

    //Authenticate the user.
    ftp1.Authenticate();

    //Send the CCC command.
    UseCCC();
}

public void UseUTF8()
{
    //Check the feeatures property to see if the server supports UTF8 encoding.
    if (ftp1.Features.Utf8Encoding)
    {
        //If the server supports UTF8 encoding, send the UTF8 command as specified in RFC2640.
        //Some servers (such as Filezilla) do not explicitly require this command but others (such as IIS) do.
        Response Resp = ftp1.Send("OPTS UTF8 ON");

        if (Resp.Code < 299)
            //If the OPTS UTF8 ON command succeeded then set the connection encoding appropriately.
            ftp1.Encoding = System.Text.Encoding.UTF8;
    }
}

public void UseCCC()
{
    //Send the CCC command
    Response Resp = ftp1.Send("CCC");

    //Check the response to see if the CCC command was successful.
    if (Resp.Code < 299)
        //Shutdown the SSL layer of the control connection. This command leaves the underlying unencrypted TCP connection open.
        ftp1.Connection.ShutdownSsl();
}
Public Sub InitConnection(ByVal state As Object)
    'Connect to the FTP server.
    ftp1.Connect()

    'Use UTF8 if available. 
    'NOTE: Some servers require the user to be authenticated before UTF8 support can be enabled,
    'if that is true then the following line must be called after the call to ftp1.Authenticate();
    UseUTF8()

    'Authenticate the user.
    ftp1.Authenticate()

    'Send the CCC command.
    UseCCC()
End Sub

Public Sub UseUTF8()
    'Check the feeatures property to see if the server supports UTF8 encoding.
    If ftp1.Features.Utf8Encoding Then
        'If the server supports UTF8 encoding, send the UTF8 command as specified in RFC2640.
        'Some servers (such as Filezilla) do not explicitly require this command but others (such as IIS) do.
        Dim Resp As Response = ftp1.Send("OPTS UTF8 ON")

        If Resp.Code < 299 Then
            'If the OPTS UTF8 ON command succeeded then set the connection encoding appropriately.
            ftp1.Encoding = System.Text.Encoding.UTF8
        End If
    End If
End Sub

Public Sub UseCCC()
    'Send the CCC command
    Dim Resp As Response = ftp1.Send("CCC")

    'Check the response to see if the CCC command was successful.
    If Resp.Code < 299 Then
        'Shutdown the SSL layer of the control connection. This command leaves the underlying unencrypted TCP connection open.
        ftp1.Connection.ShutdownSsl()
    End If
End Sub
See Also

Reference

Ftp Class
Ftp Members


PowerTCP FTP for .NET Documentation Version 6.1
© 2023 Dart Communications. All Rights Reserved.
Send comments on this topic