This page shows how to list the files of a Yaskawa Motoman controller and read their content through its web server, with the HTTP client of the SDK. It covers the YRC1000 and YRC1000micro controllers, and gives read only access: jobs, data files, parameters, logs.

## What the HTTP client does

The controller has a web server on TCP port 80. The SDK reads the file lists and the files of this server, and gives you the names, the descriptions and the text of the files. It is the simplest way to read a file: no account, no remote mode, any mode of the controller.

| Need                                    | HTTP | Other protocol                                              |
| --------------------------------------- | ---- | ----------------------------------------------------------- |
| List the files of one type              | Yes  | FTP, High Speed Ethernet Server                             |
| Name and description of the data files  | Yes  | No                                                          |
| Read a text file (job, data, parameter) | Yes  | FTP, High Speed Ethernet Server                             |
| Upload or delete a file                 | No   | [FTP](/yaskawa/documentation/ftp-transfer), [High Speed Ethernet Server](/yaskawa/documentation/hses-files) |
| Binary files, CMOS backup               | No   | FTP, High Speed Ethernet Server                             |

## Connect

### Prerequisites

- The PC reaches the controller on TCP port 80.
- Nothing else: HTTP works in teach and in play mode, without the remote mode.

### Enable HTTP

Set `Http.Enable` to `true` in `ConnectParameters`. `Connect` checks the address but does not send a request: the first method call is the first exchange.

| Parameter                  | Default | Meaning                               |
| -------------------------- | ------- | ------------------------------------- |
| `Http.Enable`              | `false` | Open the HTTP client                  |
| `Http.Port`                | `80`    | TCP port of the web server            |
| `Http.TimeoutMilliseconds` | `5000`  | Time to wait for the answer of a request |

## List the files

`GetFileList(fileExtension)` lists the files of one type. Each `FileDescription` has the `Name` of the file and, for the data and parameter files, the `Description` given by the controller.

**C# : HttpFileList**
```csharp
using UnderAutomation.Yaskawa;
using UnderAutomation.Yaskawa.Common;
using UnderAutomation.Yaskawa.Http;

public class HttpFileList
{
    static void Main()
    {
        var parameters = new ConnectParameters("192.168.0.1");
        parameters.Http.Enable = true;
        var robot = new YaskawaRobot();
        robot.Connect(parameters);

        /**/
        // Jobs: the name only
        FileDescription[] jobs = robot.Http.GetFileList(FileExtension.JOB);

        // Data files: the name and the description given by the controller
        foreach (FileDescription file in robot.Http.GetFileList(FileExtension.DAT))
            Console.WriteLine($"{file.Name}: {file.Description}"); // VAR.DAT: VARIABLE DATA
        /**/

        robot.Disconnect();
    }
}
```

**Python : HttpFileList**
```python
from underautomation.yaskawa.yaskawa_robot import YaskawaRobot
from underautomation.yaskawa.connect_parameters import ConnectParameters
from underautomation.yaskawa.common.file_extension import FileExtension

parameters = ConnectParameters("192.168.0.1")
parameters.http.enable = True
robot = YaskawaRobot()
robot.connect(parameters)

##
# Jobs: the name only
jobs = robot.http.get_file_list(FileExtension.JOB)

# Data files: the name and the description given by the controller
for file in robot.http.get_file_list(FileExtension.DAT):
    print(f"{file.name}: {file.description}")  # VAR.DAT: VARIABLE DATA
##

robot.disconnect()
```

| `FileExtension` | Files                                                       |
| --------------- | ----------------------------------------------------------- |
| `JOB`           | Jobs (`.JBI`)                                               |
| `DAT`           | Data files: variables, alarm history, I/O names... (`.DAT`) |
| `CND`           | Condition files (`.CND`)                                    |
| `PRM`           | Parameter files (`.PRM`), for example `ALL.PRM`             |
| `SYS`           | System files (`.SYS`)                                       |
| `LST`           | List files (`.LST`)                                         |
| `CSV`, `LOG`, `TXT` | Other text files                                        |

On a YRC1000micro, `GetFileList(FileExtension.DAT)` returns `VAR.DAT - VARIABLE DATA`, `ALMHIST.DAT - ALARM HISTORY DATA`, `IONAME.DAT - IO NAME DATA` and more.

## Read a file

`GetFile(name)` returns the text of a file. The SDK finds the folder of the file from its extension: `TEST.JBI` is a job, `VAR.DAT` a data file.

**C# : HttpFileGet**
```csharp
using UnderAutomation.Yaskawa;

public class HttpFileGet
{
    static void Main()
    {
        var parameters = new ConnectParameters("192.168.0.1");
        parameters.Http.Enable = true;
        var robot = new YaskawaRobot();
        robot.Connect(parameters);

        /**/
        // Text of a job: the folder is deduced from the extension
        string job = robot.Http.GetFile("TEST.JBI");

        // Variables, alarm history, parameters...
        string variables = robot.Http.GetFile("VAR.DAT");
        string alarmHistory = robot.Http.GetFile("ALMHIST.DAT");

        File.WriteAllText("TEST.JBI", job);
        /**/

        robot.Disconnect();
    }
}
```

**Python : HttpFileGet**
```python
from underautomation.yaskawa.yaskawa_robot import YaskawaRobot
from underautomation.yaskawa.connect_parameters import ConnectParameters

parameters = ConnectParameters("192.168.0.1")
parameters.http.enable = True
robot = YaskawaRobot()
robot.connect(parameters)

##
# Text of a job: the folder is deduced from the extension
job = robot.http.get_file("TEST.JBI")

# Variables, alarm history, parameters...
variables = robot.http.get_file("VAR.DAT")
alarm_history = robot.http.get_file("ALMHIST.DAT")

with open("TEST.JBI", "w", newline="") as f:
    f.write(job)
##

robot.disconnect()
```

The text is the same as the file downloaded with FTP or with the High Speed Ethernet Server. A large file takes time: `ALL.PRM` (1.4 MB) takes about 13 s on a YRC1000micro, the same as with FTP. Increase `TimeoutMilliseconds` for large files.

## Standalone client

`HttpClient` of the namespace `UnderAutomation.Yaskawa.Http` opens an HTTP client without `YaskawaRobot`. In a .NET project with implicit usings, `System.Net.Http.HttpClient` has the same name: write the full name, or add a `using` alias.

**C# : HttpStandalone**
```csharp
using UnderAutomation.Yaskawa.Common;
using UnderAutomation.Yaskawa.Http;

public class HttpStandalone
{
    static void Main()
    {
        /**/
        // An HTTP client without YaskawaRobot
        // Full name: System.Net.Http also has an HttpClient class
        var client = new UnderAutomation.Yaskawa.Http.HttpClient();
        client.Connect("192.168.0.1", new HttpConnectParameters
        {
            Port = 80,                   // default
            TimeoutMilliseconds = 5000,  // default
        });

        foreach (FileDescription file in client.GetFileList(FileExtension.PRM))
            Console.WriteLine(file);

        client.Close();
        /**/
    }
}
```

**Python : HttpStandalone**
```python
from underautomation.yaskawa.common.file_extension import FileExtension
from underautomation.yaskawa.http.http_client import HttpClient
from underautomation.yaskawa.http.http_connect_parameters import HttpConnectParameters

##
# An HTTP client without YaskawaRobot
parameters = HttpConnectParameters()
parameters.port = 80                    # default
parameters.timeout_milliseconds = 5000  # default

client = HttpClient()
client.connect("192.168.0.1", parameters)

for file in client.get_file_list(FileExtension.PRM):
    print(file)

client.close()
##
```

## Reference

**Methods of HttpClientBase**
```csharp
// Marks the client as disconnected.
void Close();

// Gets the content of a file from the robot controller. The file type is deduced from the file name extension (e.g. "PICK_JOB.JBI" queries /FGET_REQUEST/ROBOT/JOB/PICK_JOB.JBI).
string GetFile(string fileName);

// Gets the list of files of the specified type available on the robot controller.
FileDescription[] GetFileList(FileExtension fileExtension);
```

Every method also exists in an asynchronous version, with the same name followed by `Async` and an optional `CancellationToken`.

**Members of Http.FileDescription**
```csharp
public class FileDescription {
    public FileDescription()

    // Description of the file, if available.
    public string Description { get; }

    // File name including extension.
    public string Name { get; }

    // Returns the file name.
    public override string ToString()
}
```

**Members of Common.FileExtension**
```csharp
public enum FileExtension {
    // Condition files (.CND)
    CND = 2

    // CSV files (.CSV)
    CSV = 6

    // Data files (.DAT)
    DAT = 1

    // Job files (.JBI)
    JOB = 0

    // Log files (.LOG)
    LOG = 7

    // List files (.LST)
    LST = 5

    // Parameter files (.PRM)
    PRM = 4

    // System files (.SYS)
    SYS = 3

    // Text files (.TXT)
    TXT = 8
}
```

**Members of Http.HttpConnectParameters**
```csharp
public class HttpConnectParameters {
    // Initializes a new instance of the HTTP connection parameters.
    public HttpConnectParameters()

    // Default HTTP port (80).
    public const int DEFAULT_PORT = 80

    // Default timeout in milliseconds for HTTP requests (5000ms).
    public const int DEFAULT_TIMEOUT_MILLISECONDS = 5000

    // Gets or sets the HTTP port number.
    // Default: 80.
    public int Port { get; set; }

    // Gets or sets the maximum time in milliseconds to wait for a response.
    // Default: 5000ms.
    public int TimeoutMilliseconds { get; set; }
}
```

## What to read next

- [FTP](/yaskawa/documentation/ftp): upload, download and delete files.
- [Transfer files and backups](/yaskawa/documentation/how-to-transfer-files): which protocol to choose for each file task.