FTP (File Transfer Protocol) provides direct access to the Fanuc controller's internal file system. The SDK uses FTP to transfer files (programs, backups) and to read and decode diagnostic data, variables, registers, and safety status.

## Key features

- **File management**: Upload, download, delete, rename files and directories
- **Variable reading**: Read all system variables in bulk from .va files
- **Registers**: Read numeric, position, and string registers
- **Diagnostics**: Safety status, I/O state, current position, error history
- **Installed features**: Detect available options on the controller

## Quick example

**C# : Ftp**
```csharp
using UnderAutomation.Fanuc;
using UnderAutomation.Fanuc.Common.Files.Diagnosis;

  public class Ftp
  {
    static void Main()
    {
      // Create a new Fanuc robot instance
      FanucRobot robot = new FanucRobot();

      // Set connection parameters
      ConnectionParameters parameters = new ConnectionParameters("192.168.0.1");
      parameters.Ftp.Enable = true;
      parameters.Ftp.FtpUser = "user";
      parameters.Ftp.FtpPassword = "ftp password";

      // Connect to the robot
      robot.Connect(parameters);

      /**/
      IOState ioState = robot.Ftp.GetIOState();

      // Read a variable
      var variableFiles = robot.Ftp.GetAllVariables();
      foreach (var variableFile in variableFiles)
        foreach (var variable in variableFile.Variables)
          Console.WriteLine($"{variable.Name} = {variable.Value}");

      // Read system variable $RMT_MASTER
      int remoteMode = robot.Ftp.KnownVariableFiles.GetSystemFile().RmtMaster;

      // Read safety status
      SafetyStatus safetyStatus = robot.Ftp.GetSafetyStatus();
      Console.WriteLine($"Emergency Stop: {safetyStatus.ExternalEStop}");
      Console.WriteLine($"Teach Pendant Enabled: {safetyStatus.TPEnable}");

      // Get current position for each arm (Joints, World position of each tool, user frame positions)
      CurrentPosition currentPosition = robot.Ftp.GetCurrentPosition();

      // Upload a TP program to the controller
      robot.Ftp.DirectFileHandling.UploadFileToController(@"C:\Programs\MyPrg.tp", "md:/MyPrg.tp");

      // Download a file from the robot
      robot.Ftp.DirectFileHandling.DownloadFileFromController("md:/Backup.va", @"C:\Backup\Backup.va");

      // Delete a file on the robot
      robot.Ftp.DirectFileHandling.DeleteFile("md:/OldProgram.tp");
      /**/
    }

  }
```

**Python : Ftp**
```python
from underautomation.fanuc.fanuc_robot import FanucRobot
from underautomation.fanuc.connection_parameters import ConnectionParameters

robot = FanucRobot()
parameters = ConnectionParameters("192.168.0.1")
parameters.ftp.enable = True
parameters.ftp.ftp_user = ""
parameters.ftp.ftp_password = ""
robot.connect(parameters)

##
# Read I/O state
io_state = robot.ftp.get_io_state()

# Read all variables from all files
all_variables = robot.ftp.get_all_variables()
for file in all_variables:
    for variable in file.variables:
        print(f"{variable.name} = {variable.value}")

# Access well-known system variables
rmt_master = robot.ftp.known_variable_files.get_system_file().rmt_master

# Read safety status
safety_status = robot.ftp.get_safety_status()
print(f"Emergency Stop: {safety_status.external_e_stop}")
print(f"Teach Pendant Enabled: {safety_status.tp_enable}")

# Read current position (joints, world, user frames)
current_position = robot.ftp.get_current_position()

# Upload a TP program to the controller
robot.ftp.direct_file_handling.upload_file_to_controller("C:/Programs/MyPrg.tp", "md:/MyPrg.tp")

# Download a file from the robot
robot.ftp.direct_file_handling.download_file_from_controller("C:/Backup/Backup.va", "md:/Backup.va")

# Delete a file
robot.ftp.direct_file_handling.delete_file("md:/OldProgram.tp")
##
```

## Connection

**C# : FtpConnection**
```csharp
using UnderAutomation.Fanuc;
using UnderAutomation.Fanuc.Ftp;

public class FtpConnection
{
    static void Main()
    {
        /**/
        // Via FanucRobot
        var robot = new FanucRobot();
        var parameters = new ConnectionParameters("192.168.0.1");
        parameters.Ftp.Enable = true;
        parameters.Ftp.FtpUser = "";          // usually empty
        parameters.Ftp.FtpPassword = "";      // usually empty
        parameters.Ftp.FtpTimeoutMs = 30000;  // optional, default is 30 seconds
        robot.Connect(parameters);

        // Or standalone
        var ftp = new FtpClient();
        ftp.Connect("192.168.0.1", "", "");
        /**/
    }
}
```

**Python : FtpConnection**
```python
from underautomation.fanuc.fanuc_robot import FanucRobot
from underautomation.fanuc.connection_parameters import ConnectionParameters
from underautomation.fanuc.ftp.ftp_client import FtpClient

##
# Via FanucRobot
robot = FanucRobot()
parameters = ConnectionParameters("192.168.0.1")
parameters.ftp.enable = True
parameters.ftp.ftp_user = ""          # usually empty
parameters.ftp.ftp_password = ""      # usually empty
parameters.ftp.ftp_timeout_ms = 30000  # optional, default is 30 seconds
robot.connect(parameters)

# Or standalone
ftp = FtpClient()
ftp.connect("192.168.0.1", "", "")
##
```

The `FtpTimeoutMs` property controls the connection, read, and data transfer timeouts. The default is 30,000 ms (30 seconds). Lower it for faster failure detection on unreachable controllers, or raise it for slow networks.

## Limitations

- **Read-only for most data**: Variables and diagnostics are read-only via FTP. Use Telnet, SNPX, or CGTP to write values
- **Slower than SNPX**: FTP transfers entire files rather than individual values
- **No real-time data**: Data represents a snapshot at the time of the FTP request

## Next steps

- [File management](/fanuc/documentation/ftp-file-management) : Upload, download, delete files
- [Diagnostics & variables](/fanuc/documentation/ftp-diagnostics) : Safety status, registers, variables

## API reference

**Members of Ftp.FtpClient**
```csharp
public class FtpClient : FtpClientBase {
    // Instanciate a new FTP client connection
    public FtpClient()

    // Connect to a robot
    public void Connect(string ip, string user, string password, int port = 21, int timeoutMs = 30000)
}
```

**Members of Ftp.Internal.FtpClientBase**
```csharp
public abstract class FtpClientBase : FileClientBase {
    // Indicates that FTP connection is active
    public bool Connected { get; }

    // Contains methods to manipulate files and folders on the controller (upload, download, delete, ...)
    public FtpDirectFileHandling DirectFileHandling { get; }

    // Disconnects from FTP server
    public void Disconnect()

    // Get the list of all variable file names available on the controller
    public override string[] EnumerateVariableFileNames()

    // Get a list of all variable files on controller
    public FtpListItem[] EnumerateVariableFiles()

    // Connect robot IP address or host name
    public override string IP { get; }

    // Controller language (default is English)
    public Languages Language { get; set; }
}
```