This page is only available in English.
File management
Upload, download, delete, rename files and directories on the Fanuc robot controller via FTP.
Upload, download, delete, and rename files and directories on the Fanuc robot controller via FTP.
Upload files
parameters.Ftp.FtpPassword = "";robot.Connect(parameters);// Upload a TP program to the controller (overwrites if it already exists)robot.Ftp.DirectFileHandling.UploadFileToController(@"C:\Programs\MyPrg.tp", "md:/MyPrg.tp");// Skip upload if the file already exists on the controllerrobot.Ftp.DirectFileHandling.UploadFileToController(@"C:\Programs\MyPrg.tp", "md:/MyPrg.tp",existsBehavior: FtpExistsBehavior.Skip);// Resume a partial upload (appends missing bytes)robot.Ftp.DirectFileHandling.UploadFileToController(@"C:\LargeFile.tp", "md:/LargeFile.tp",existsBehavior: FtpExistsBehavior.Append);// Upload from a byte arraybyte[] fileBytes = File.ReadAllBytes(@"C:\Programs\MyPrg.tp");robot.Ftp.DirectFileHandling.UploadFileToController(fileBytes, "md:/MyPrg.tp",existsBehavior: FtpExistsBehavior.Overwrite);// Upload multiple files to a directoryrobot.Ftp.DirectFileHandling.UploadFilesToController(new[] { @"C:\file1.tp", @"C:\file2.tp" },"md:/programs/");}}
Click to see the full code
Download files
parameters.Ftp.FtpPassword = "";robot.Connect(parameters);// Download to a local filerobot.Ftp.DirectFileHandling.DownloadFileFromController(@"C:\Backup\Backup.va", "md:/Backup.va");// Download to a byte arraybyte[] data;robot.Ftp.DirectFileHandling.DownloadFileFromController(out data, "md:/MyPrg.tp");// Download multiple filesrobot.Ftp.DirectFileHandling.DownloadFilesFromController(@"C:\Backup\",new[] { "md:/file1.tp", "md:/file2.va" });}}
Click to see the full code
Delete, list, and manage directories
parameters.Ftp.FtpPassword = "";robot.Connect(parameters);// Delete a filerobot.Ftp.DirectFileHandling.DeleteFile("md:/OldProgram.tp");// Delete a directory and its contentsrobot.Ftp.DirectFileHandling.DeleteDirectory("md:/OldFolder");// Check if a directory existsbool exists = robot.Ftp.DirectFileHandling.DirectoryExists("md:/programs");// Create a directoryrobot.Ftp.DirectFileHandling.CreateDirectory("md:/NewFolder");// List files and directoriesFtpListItem[] items = robot.Ftp.DirectFileHandling.GetListing("md:/");foreach (var item in items){Console.WriteLine($"{item.Name} ({item.Type}) - {item.Size} bytes");}// Rename or move a filerobot.Ftp.DirectFileHandling.Rename("md:/old.tp", "md:/new.tp");}}
Click to see the full code
Complete example
using UnderAutomation.Fanuc;public class FtpFileManagement{static void Main(){FanucRobot robot = new FanucRobot();ConnectionParameters parameters = new ConnectionParameters("192.168.0.1");parameters.Ftp.Enable = true;parameters.Ftp.FtpUser = "";parameters.Ftp.FtpPassword = "";robot.Connect(parameters);// Upload a TP program to the controllerrobot.Ftp.DirectFileHandling.UploadFileToController(@"C:\Programs\MyPrg.tp", "md:/MyPrg.tp");// Download a file from the robotrobot.Ftp.DirectFileHandling.DownloadFileFromController(@"C:\Backup\Backup.va", "md:/Backup.va");// Delete a filerobot.Ftp.DirectFileHandling.DeleteFile("md:/OldProgram.tp");// List files in a directoryvar items = robot.Ftp.DirectFileHandling.GetListing("md:/");foreach (var item in items)Console.WriteLine($"{item.Name} ({item.Type})");// Create and delete directoriesrobot.Ftp.DirectFileHandling.CreateDirectory("md:/NewFolder");// Rename a filerobot.Ftp.DirectFileHandling.Rename("md:/old.tp", "md:/new.tp");// Check file existencebool exists = robot.Ftp.DirectFileHandling.FileExists("md:/MyPrg.tp");}}
API reference
Methods to handle files on a Fanuc controller (upload, download, delete, enumerate, ...)
| Member | Type | Description |
|---|---|---|
CreateDirectory(string) Method | void | Creates a directory on the controller. If the preceding directories do not exist, then they are created.
|
DeleteDirectory(string) Method | void | Deletes the specified directory and all its contents.
|
DeleteFile(string) Method | void | Deletes a file on the controller
|
DirectoryExists(string) Method | bool | Tests if the specified directory exists on the controller. This method works by trying to change the working directory to the path specified. If it succeeds, the directory is changed back to the old working directory and true is returned. False is returned otherwise and since the CWD failed it is assumed the working directory is still the same.
|
DownloadFileFromController(out byte[], string, OnProgressDelegate) Method | bool | Downloads the specified file and return the raw byte array. High-level API that takes care of various edge cases internally. Supports very large files since it downloads data in chunks.
|
DownloadFileFromController(Stream, string, OnProgressDelegate) Method | bool | Downloads the specified file into the specified stream. High-level API that takes care of various edge cases internally. Supports very large files since it downloads data in chunks.
|
DownloadFileFromController(string, string, OnProgressDelegate) Method | bool | Downloads the specified file onto the local file system. High-level API that takes care of various edge cases internally. Supports very large files since it downloads data in chunks. It overwrites the file if it already exists.
|
DownloadFilesFromController(string, string[], OnProgressDelegate) Method | string[] | Downloads the specified files into a local single directory. High-level API that takes care of various edge cases internally. Supports very large files since it downloads data in chunks.
|
FileExists(string) Method | bool | Checks if a file exists on the controller.
|
GetListing(string) Method | FtpListItem[] | Gets a file listing from the controller. Each FtpListItem object returned contains information about the file that was able to be retrieved.
|
GetObjectInfo(string) Method | FtpListItem | Returns information about a file system object. Returns null if the controller response can't be parsed or the controller returns a failure completion code. The error for a failure is logged with FtpTrace. No exception is thrown on error because that would negate the usefulness of this method for checking for the existence of an object.
|
Rename(string, string) Method | void | Renames an object on the remote file system. Throws exceptions if the file does not exist, or if the destination file already exists.
|
UploadFileToController(byte[], string, bool, OnProgressDelegate, FtpExistsBehavior) Method | bool | Uploads the specified byte array as a file onto the controller. High-level API that takes care of various edge cases internally. Supports very large files since it uploads data in chunks. It overwrites file if it already exists.
|
UploadFileToController(Stream, string, bool, OnProgressDelegate, FtpExistsBehavior) Method | bool | Uploads the specified stream as a file onto the controller. High-level API that takes care of various edge cases internally. Supports very large files since it uploads data in chunks. It overwrites file if it already exists.
|
UploadFileToController(string, string, bool, OnProgressDelegate, FtpExistsBehavior) Method | bool | Uploads the specified file directly onto the controller. High-level API that takes care of various edge cases internally. Supports very large files since it uploads data in chunks.
|
UploadFilesToController(string[], string, OnProgressDelegate) Method | string[] | Uploads the given file paths to a single folder on the controller. All files are placed directly into the given folder regardless of their path on the local filesystem. High-level API that takes care of various edge cases internally. Supports very large files since it uploads data in chunks.
|
Represents a file system object on the controller
| Member | Type | Description |
|---|---|---|
Chmod Property read only | int | Gets the file permissions in the CHMOD format. |
Created Property read only | DateTime | Gets the created date of the object. |
FullName Property read only | string | Gets the full path name to the object. |
Modified Property read only | DateTime | Gets the last write time of the object. |
Name Property read only | string | Gets name to the object. |
Size Property read only | long | Gets the size of the object. Only a few files (like *.tp or *.df) have a size that can be retrieved, for most files this is 0 even if they are not empty. For directories this is always 0. |
Type Property read only | FtpFileSystemObjectType | Gets the type of file system object. |