PowerTCP FTP for .NET
Send(String) Method
Example 



Command to send (do not include CR/LF).
Send the provided command over the control connection and return the response.
Syntax
Public Function Send( _
   ByVal command As String _
) As Response
Dim instance As Ftp
Dim command As String
Dim value As Response
 
value = instance.Send(command)
public Response Send( 
   string command
)
public:
Response^ Send( 
   String^ command
) 

Parameters

command
Command to send (do not include CR/LF).

Return Value

Remarks
For example, if you set Session.AutoType to false, you can manually send the TYPE command by calling Send("TYPE I") for binary or Send("TYPE A") for ascii. This gives you complete extensibility for servers that support custom commands. No FtpProtocolException is thrown, so the user should always check for a valid response code.
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 4.7
© 2018 Dart Communications. All Rights Reserved.
Send comments on this topic