OpenFile Event
This event instructs the application to handle the file open request.
Syntax
public event OnOpenFileHandler OnOpenFile; public delegate void OnOpenFileHandler(object sender, SftpserverOpenFileEventArgs e); public class SftpserverOpenFileEventArgs : EventArgs { public long ConnectionID { get; } public string Path { get; } public int Modes { get; } public int Access { get; } public int OperationStatus { get; set; } public string Handle { get; set; } }
Public Event OnOpenFile As OnOpenFileHandler Public Delegate Sub OnOpenFileHandler(sender As Object, e As SftpserverOpenFileEventArgs) Public Class SftpserverOpenFileEventArgs Inherits EventArgs Public ReadOnly Property ConnectionID As Long Public ReadOnly Property Path As String Public ReadOnly Property Modes As Integer Public ReadOnly Property Access As Integer Public Property OperationStatus As Integer Public Property Handle As String End Class
Remarks
This event is fired when a file open request is received from the client and needs to be handled (virtualized) by the server. The ConnectionID parameter specifies in which session the request was received, and Path specifies the location of the file.
Modes can be a combination of one or several file open mode flags:
cfmRead | 1 |
cfmWrite | 2 |
cfmAppend | 4 |
cfmCreate | 8 |
cfmTruncate | 16 |
cfmExcl | 32 |
cfmText | 64 |
cfmOpenOrCreate | 128 |
cfmAppendAtomic | 256 |
cfmNoFollow | 512 |
cfmDeleteOnClose | 1024 |
Different client applications may provide different selections of mode flags. For example, some clients specify (cfmCreate + cfmTruncate) when overwriting files, whereas others would specify cfmOpenOrCreate. Please make sure your code is prepared to receive different combinations of flags here and handles them gracefully.
The Access parameter provides additional file access modifiers:
cfaReadLock | 1 |
cfaWriteLock | 2 |
cfaDeleteLock | 4 |
cfaBlockAdvisory | 8 |
The Handle string represents a unique identifier of the opened file, similar to file handles used in Windows or Unix APIs. Handles are unique across all files opened at the same time. Component generates handles automatically, but you can update the auto-generated values with your own in this event handler (just remember to keep them unique).
Set OperationStatus parameter in accordance with the outcome of the operation to one of the values given below:
ostOk | 1 | |
ostNoSuchFile | 2 | |
ostAccessDenied | 3 | |
ostWriteProtect | 4 | |
ostUnsupported | 5 | |
ostInvalidParameter | 6 | |
ostEOF | 7 |