SocketTools .NET Edition

FtpClient.OpenFile Method (String, FtpOpenMode, Int32)

Open an existing file or create a new file on the server.

[Visual Basic]
Overloads Public Function OpenFile( _
   ByVal remoteFile As String, _
   ByVal openMode As FtpOpenMode, _
   ByVal offset As Integer _
) As Boolean
[C#]
public bool OpenFile(
   string remoteFile,
   FtpOpenMode openMode,
   int offset
);

Parameters

remoteFile
A string that specifies the name of the file on the server. The filename cannot contain any wildcard characters and must follow the naming conventions of the operating system the server is hosted on.
openMode
An FtpOpenMode enumeration which specifies how the file should be accessed on the server.
offset
An integer value which specifies the byte offset where the file transfer should begin. If this argument is omitted, this specifies that the file transfer should start at the beginning of the file. A value greater than zero is typically used to restart a transfer that has not completed successfully. Note that specifying a non-zero offset requires that the server support the REST command to restart transfers.

Return Value

This method returns a boolean value. If the method succeeds, the return value is true. If the method fails, the return value is false. To get extended error information, check the value of the LastError property.

Remarks

The OpenFile method opens an existing file or creates a new file on the remote server using the specified file name. The Read method may then be used to read data from the file and the Write method may be used to write data to the file. Once the all of the data has been read or written, the CloseFile method must be called to close the data channel.

It is strongly recommended that most applications use the GetFile or PutFile methods to perform file transfers. These methods are easier to use, and have internal optimizations that improves the overall data transfer rate when compared to implementing the file transfer code in your own application.

When a file is created on the remote server, the file ownership and access rights are determined by the server. Some servers may provide a method to change these attributes through site-specific commands. Refer to the server's operating system documentation for more information about what commands may be available.

See Also

FtpClient Class | SocketTools Namespace | FtpClient.OpenFile Overload List