The mi_file_to_file() function

The mi_file_to_file() function copies files between the database server and a client computer.

Syntax

char *mi_file_to_file(conn, fromfile, from_open_mode, tofile, to_open_mode)
   MI_CONNECTION *conn;
   const char *fromfile;
   mi_integer open_mode;
   const char *tofile;
   mi_integer toflags;
conn
A pointer to a connection descriptor established by a previous call to mi_open() or mi_server_connect().
fromfile
The full path name of the source file.
from_open_mode
A bit-mask argument to indicate how to open the fromfile file and the location of this file. For a list of valid file-mode constants, see the following "Usage" section.
tofile
The full path name of the destination file.
to_open_mode
A bit-mask argument to indicate how to open the tofile file and the location of this file. For a list of valid file-mode constants, see the table in the following "Usage" section.
Valid in client LIBMI application? Valid in user-defined routine?
No Yes

Usage

You can use the mi_file_to_file() function to copy a source file to a target file:
  • From a server computer to a client computer
  • From a client computer to a server computer
  • From the server computer to the server computer

The mi_file_to_file() function does not support copies from client computer to client computer.

You can include environment variables in the fromfile and tofile paths with the following syntax:
$ENV_VAR

These environment variables must be set in the server environment; that is, they must be set before the database server starts.

The mi_file_to_file() function can create the target files on either the server computer or the client computer. The file-mode flag values for the from_open_mode and to_open_mode arguments indicate the access modes and locations of the source and target files. Valid values include the following file-mode constants.
MI_O_EXCL
Open the file only if fname_spec does not exist. Raise an exception if fname_spec does exist.
MI_O_TRUNC
Truncate the file, if it exists.
MI_O_APPEND
Append to the file, if it exists.
MI_O_RDONLY
Open the file in read-only mode (from_open_mode only).
MI_O_RDWR
Open the file in read/write mode.
MI_O_WRONLY
Open the file in write-only mode (to_open_mode only).
MI_O_BINARY
Process the data as binary data (to_open_mode only).
MI_O_TEXT
Process the data as text data (not binary, which is used if you do not specify MI_O_TEXT).
MI_O_SERVER_FILE
The fname_spec file is created on the server computer. The file mode is read/write for all users. The file owner is the client user ID.
MI_O_CLIENT_FILE
The fname_spec file is created on the client computer. The file owner is the client user and file permissions will be consistent with the umask setting of the client.
The default to_open_mode value follows:
MI_O_CLIENT_FILE | MI_O_WRONLY | MI_O_TRUNC

The from_open_mode and to_open_mode must include either MI_O_CLIENT_FILE or MI_O_SERVER_FILE, but not both. Because mi_file_to_file() does not support copies from client computer to client computer, from_open_mode and to_open_mode cannot both be set to MI_O_CLIENT_FILE.

Return values

A char pointer
A pointer to the path name of the destination file.
NULL
The function was not successful.

The mi_file_to_file() function does not throw an MI_Exception event when it encounters a runtime error. Therefore, it does not cause callbacks to start.