5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2001 - 2007 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
23 /****h* silcsftp/SILC SFTP Interface
27 * SILC SFTP Interface is the implementation of the Secure File Transfer
28 * Protocol (or SSH File Transfer Protocol). The interface defines the SFTP
29 * client and the SFTP server. The SFTP is the mandatory file transfer
30 * protocol in the SILC protocol, and when used in SILC the SFTP packets are
31 * encapsulated into SILC packets. The SFTP server implementation is
32 * filesystem independent and generic interface is defined to represent
35 * The SilcSFTP context is the actual SFTP client or SFTP server, and each
36 * SFTP session should create its own SFTP context.
38 * The SILC SFTP library is a generic SFTP implementation and not directly
39 * related to either SILC or SSH. It could be used for any general purpose
44 /****s* silcsftp/SilcSFTPAPI/SilcSFTP
48 * typedef struct SilcSFTPStruct *SilcSFTP;
52 * This context is the actual SFTP client and SFTP server, and is
53 * allocated by silc_sftp_client_start or silc_sftp_server_start and
54 * given as argument usually to all silc_sftp_* functions. It is freed
55 * by the silc_sftp_client_shutdown or silc_sftp_server_shutdown
59 typedef struct SilcSFTPStruct *SilcSFTP;
61 /****d* silcsftp/SilcSFTPAPI/SilcSFTPVersion
65 * typedef SilcUInt32 SilcSFTPVersion;
72 typedef SilcUInt32 SilcSFTPVersion;
74 /* SFTP protocol version */
75 #define SILC_SFTP_PROTOCOL_VERSION 3
77 /****d* silcsftp/SilcSFTPAPI/SilcSFTPStatus
81 * typedef enum { ... } SilcSFTPStatus
85 * SFTP protocol status types. These enumerations is used to indicate
86 * the status of request. The server can send these to the client when
87 * client has requested an operation.
92 SILC_SFTP_STATUS_OK = 0, /* Operation successful */
93 SILC_SFTP_STATUS_EOF = 1, /* No more data available */
94 SILC_SFTP_STATUS_NO_SUCH_FILE = 2, /* File does not exist */
95 SILC_SFTP_STATUS_PERMISSION_DENIED = 3, /* No sufficient permissions */
96 SILC_SFTP_STATUS_FAILURE = 4, /* Operation failed */
97 SILC_SFTP_STATUS_BAD_MESSAGE = 5, /* Bad message received */
98 SILC_SFTP_STATUS_NO_CONNECTION = 6, /* No connection to remote */
99 SILC_SFTP_STATUS_CONNECTION_LOST = 7, /* Connection lost to server */
100 SILC_SFTP_STATUS_OP_UNSUPPORTED = 8, /* Operation unsupported */
101 SILC_SFTP_STATUS_INVALID_HANDLE = 9, /* Invalid file handle */
102 SILC_SFTP_STATUS_NO_SUCH_PATH = 10, /* Path does not exist */
103 SILC_SFTP_STATUS_FILE_ALREADY_EXIST = 11, /* File already exists */
104 SILC_SFTP_STATUS_WRITE_PROTECT = 12, /* Read-only or protected */
105 SILC_SFTP_STATUS_NO_MEDIA = 13, /* No media available */
106 SILC_SFTP_STATUS_NO_SPACE_ON_DEVICE = 14, /* No space on device */
107 SILC_SFTP_STATUS_QUOTA_EXCEEDED = 15, /* Quota limit reached */
108 SILC_SFTP_STATUS_UNKNOWN_PRINCIBLE = 16, /* Unknown princible */
109 SILC_SFTP_STATUS_LOCK_CONFLICT = 17, /* File already locked */
110 SILC_SFTP_STATUS_NOT_EMPTY = 18, /* Directory not empty */
111 SILC_SFTP_STATUS_NOT_A_DIRECTORY = 19, /* Not a directory */
112 SILC_SFTP_STATUS_INVALID_FILENAME = 20, /* Invalid filename */
113 SILC_SFTP_STATUS_LINK_LOOP = 21, /* Too many symlinks */
114 SILC_SFTP_STATUS_CANNOT_DELETE = 22, /* Could not delete file */
115 SILC_SFTP_STATUS_INVALID_PARAMETER = 23, /* Invalid parameter */
116 SILC_SFTP_STATUS_FILE_IS_A_DIRECTORY = 24, /* File is a directory file */
117 SILC_SFTP_STATUS_BR_LOCK_CONFLICT = 25, /* Byte range lock conflict */
118 SILC_SFTP_STATUS_BR_LOCK_REFUSED = 26, /* Byte range lock refused */
119 SILC_SFTP_STATUS_DELETE_PENDING = 27, /* File is being deleted */
120 SILC_SFTP_STATUS_FILE_CORRUPT = 28, /* File is corrupted */
124 /****d* silcsftp/SilcSFTPAPI/SilcSFTPFileOperation
128 * typedef enum { ... } SilcSFTPFileOperation
132 * SFTP protocol file operation flags. These enumerations can be used
133 * by the client when client is opening an file, to indicate how it
134 * would like to open the file.
139 SILC_SFTP_FXF_READ = 0x00000001, /* Reading */
140 SILC_SFTP_FXF_WRITE = 0x00000002, /* Writing */
141 SILC_SFTP_FXF_APPEND = 0x00000004, /* Appending to end of file */
142 SILC_SFTP_FXF_CREAT = 0x00000008, /* Create if doesn't exist */
143 SILC_SFTP_FXF_TRUNC = 0x00000010, /* Truncate if exists */
144 SILC_SFTP_FXF_EXCL = 0x00000020, /* Don't create if exists */
145 } SilcSFTPFileOperation;
148 /****s* silcsftp/SilcSFTPAPI/SilcSFTPAttributes
152 * typedef struct { ... } *SilcSFTPAttributes, SilcSFTPAttributesStruct;
156 * SFTP File attributes structure represents the attributes for a file.
157 * This structure can be used by the client to send attributes to the
158 * server, and by server to return file attributes to the client.
161 typedef struct SilcSFTPAttributesObject {
162 SilcUInt32 flags; /* Flags to indicate present attributes */
163 SilcUInt64 size; /* Sife of the file in bytes */
164 SilcUInt32 uid; /* Unix user ID */
165 SilcUInt32 gid; /* Unix group ID */
166 SilcUInt32 permissions; /* POSIX file permission bitmask */
167 SilcUInt32 atime; /* Access time of file */
168 SilcUInt32 mtime; /* Modification time of file */
170 SilcUInt32 extended_count; /* Extended type and data count */
171 SilcBuffer *extended_type;
172 SilcBuffer *extended_data;
173 } *SilcSFTPAttributes, SilcSFTPAttributesStruct;
175 /****s* silcsftp/SilcSFTPAPI/SilcSFTPName
179 * typedef struct { ... } *SilcSFTPName, SilcSFTPNameStruct
183 * SFTP Name structure represents the name reply received from the server.
184 * It includes the returned file(s) short and long file names and
185 * attributes for the file(s). This is returned by the server for
186 * example when reading the contents of a directory.
189 typedef struct SilcSFTPNameObject {
191 char **long_filename;
192 SilcSFTPAttributes *attrs;
193 SilcUInt32 count; /* Number of files */
194 } *SilcSFTPName, SilcSFTPNameStruct;
196 /****s* silcsftp/SilcSFTPAPI/SilcSFTPHandle
200 * typedef struct SilcSFTPHandleStruct *SilcSFTPHandle;
204 * This context represents an open file handle and is allocated by
205 * the library. The application receives this context in the
206 * SilcSFTPHandleCallback function.
209 typedef struct SilcSFTPHandleStruct *SilcSFTPHandle;
211 /****f* silcsftp/SilcSFTPAPI/SilcSFTPVersionCallback
215 * typedef void (*SilcSFTPVersionCallback)(SilcSFTP sftp,
216 * SilcSFTPStatus status,
217 * SilcSFTPVersion version,
222 * Version callback is called at the protocol initialization phase when
223 * the server returns the version of the protocol. The `version' indicates
224 * the version of the protocol.
227 typedef void (*SilcSFTPVersionCallback)(SilcSFTP sftp,
228 SilcSFTPStatus status,
229 SilcSFTPVersion version,
232 /****f* silcsftp/SilcSFTPAPI/SilcSFTPErrorCallback
236 * typedef void (*SilcSFTPErrorCallback)(SilcSFTP sftp,
237 * SilcSFTPStatus status,
242 * Error callback is called if a connection error occurs during SFTP
243 * session. If the connection or stream is closed this callback is
244 * called. Other errors are delivered in other callbacks. Only the
245 * SILC_SFTP_STATUS_EOF or SILC_SFTP_STATUS_NO_CONNECTION is delivered
249 typedef void (*SilcSFTPErrorCallback)(SilcSFTP sftp,
250 SilcSFTPStatus status,
253 /****f* silcsftp/SilcSFTPAPI/SilcSFTPStatusCallback
257 * typedef void (*SilcSFTPStatusCallback)(SilcSFTP sftp,
258 * SilcSFTPStatus status,
259 * const char *message,
260 * const char *language_tag,
265 * Status callback is called every time server returns a status packet
266 * for a request the client has made. The `status' indicates the type
267 * of the status. The `message' is optional error message received from
268 * the server, in language indicated by the `language_tag'. Both of
269 * these pointers may be NULL.
272 typedef void (*SilcSFTPStatusCallback)(SilcSFTP sftp,
273 SilcSFTPStatus status,
275 const char *language_tag,
278 /****f* silcsftp/SilcSFTPAPI/SilcSFTPHandleCallback
282 * typedef void (*SilcSFTPHandleCallback)(SilcSFTP sftp,
283 * SilcSFTPStatus status,
284 * SilcSFTPHandle handle,
289 * Handle callback is called when the server returns a handle to the
290 * client as a result of some request client has made. The `handle'
291 * is the file handle and the application can use it to perform file
292 * operations for the handle. Each of the returned handle must be
293 * also closed at some point with silc_sftp_close.
296 typedef void (*SilcSFTPHandleCallback)(SilcSFTP sftp,
297 SilcSFTPStatus status,
298 SilcSFTPHandle handle,
301 /****f* silcsftp/SilcSFTPAPI/SilcSFTPDataCallback
305 * typedef void (*SilcSFTPDataCallback)(SilcSFTP sftp,
306 * SilcSFTPStatus status,
307 * const unsigned char *data,
308 * SilcUInt32 data_len,
313 * Data callback is called when data packet is received from the server.
314 * This is called for example when application is reading a file from
315 * the server. The `data' is the raw data of length of `data_len'.
318 typedef void (*SilcSFTPDataCallback)(SilcSFTP sftp,
319 SilcSFTPStatus status,
320 const unsigned char *data,
324 /****f* silcsftp/SilcSFTPAPI/SilcSFTPNameCallback
328 * typedef void (*SilcSFTPNameCallback)(SilcSFTP sftp,
329 * SilcSFTPStatus status,
330 * const SilcSFTPName name,
335 * Name callback is called when directory is being read by the client.
336 * The server returns one or more file names in one reply. These file
337 * names are saved in the `filename' structures with their short and
338 * long name format, and with file attributes.
341 typedef void (*SilcSFTPNameCallback)(SilcSFTP sftp,
342 SilcSFTPStatus status,
343 const SilcSFTPName name,
346 /****f* silcsftp/SilcSFTPAPI/SilcSFTPAttrCallback
350 * typedef void (*SilcSFTPAttrCallback)(SilcSFTP sftp,
351 * SilcSFTPStatus status,
352 * const SilcSFTPAttributes attrs,
357 * Attributes callback is called when the server returns the attributes
358 * for a file the client has requested. The attributes are saved in
359 * the `attrs' structure.
362 typedef void (*SilcSFTPAttrCallback)(SilcSFTP sftp,
363 SilcSFTPStatus status,
364 const SilcSFTPAttributes attrs,
367 /****f* silcsftp/SilcSFTPAPI/SilcSFTPExtendedCallback
371 * typedef void (*SilcSFTPExtendedCallback)(SilcSFTP sftp,
372 * SilcSFTPStatus status,
373 * const unsigned char *data,
374 * SilcUInt32 data_len,
379 * Extended request callback is called when client sends extended
380 * request to the server. The `data' is arbitrary data returned by the
381 * server and its encoding is the extended request specific.
384 typedef void (*SilcSFTPExtendedCallback)(SilcSFTP sftp,
385 SilcSFTPStatus status,
386 const unsigned char *data,
391 /* SFTP Client Interface */
393 /****f* silcsftp/SilcSFTPAPI/silc_sftp_client_start
397 * SilcSFTP silc_sftp_client_start(SilcStream stream,
398 * SilcSchedule schedule,
399 * SilcSFTPVersionCallback version_cb,
400 * SilcSFTPErrorCallback error_cb,
405 * Starts SFTP client and returns context to it. The version callback
406 * indicated by the `version_cb' will be called after the SFTP session has
407 * been started and server has returned the version of the protocol. The
408 * SFTP client context is returned in the callback too. This returns the
409 * allocated SFTP client context or NULL on error. The `stream' will be
410 * used to read and write the SFTP packets. The `error_cb' will be called
411 * in case a stream error occurs, such as end of stream.
413 * If `schedule' is NULL this will call silc_schedule_get_global to try to
414 * get global scheduler.
417 SilcSFTP silc_sftp_client_start(SilcStream stream,
418 SilcSchedule schedule,
419 SilcSFTPVersionCallback version_cb,
420 SilcSFTPErrorCallback error_cb,
423 /****f* silcsftp/SilcSFTPAPI/silc_sftp_client_shutdown
427 * void silc_sftp_client_shutdown(SilcSFTP sftp);
431 * Shutdown's the SFTP client. The caller is responsible of closing
432 * the associated stream. The SFTP context is freed and is invalid after
433 * this function returns.
436 void silc_sftp_client_shutdown(SilcSFTP sftp);
438 /****f* silcsftp/SilcSFTPAPI/silc_sftp_open
442 * void silc_sftp_open(SilcSFTP sftp,
443 * const char *filename,
444 * SilcSFTPFileOperation pflags,
445 * SilcSFTPAttributes attrs,
446 * SilcSFTPHandleCallback callback,
451 * Open a file indicated by the `filename' with flags indicated by the
452 * `pflags', and with attributes indicated by the `attsr'. Calls the
453 * `callback' to return the opened file handle.
456 void silc_sftp_open(SilcSFTP sftp,
457 const char *filename,
458 SilcSFTPFileOperation pflags,
459 SilcSFTPAttributes attrs,
460 SilcSFTPHandleCallback callback,
463 /****f* silcsftp/SilcSFTPAPI/silc_sftp_close
467 * void silc_sftp_close(SilcSFTP sftp,
468 * SilcSFTPHandle handle,
469 * SilcSFTPStatusCallback callback,
474 * Closes the file indicated by the file handle `handle'. Calls the
475 * `callback' to indicate the status of the closing.
478 void silc_sftp_close(SilcSFTP sftp,
479 SilcSFTPHandle handle,
480 SilcSFTPStatusCallback callback,
483 /****f* silcsftp/SilcSFTPAPI/silc_sftp_read
487 * void silc_sftp_read(SilcSFTP sftp,
488 * SilcSFTPHandle handle,
491 * SilcSFTPDataCallback callback,
496 * Reads data from the file indicated by the file handle `handle' starting
497 * from the offset of `offset' at most `len' bytes. The `callback' is
498 * called to return the read data.
501 void silc_sftp_read(SilcSFTP sftp,
502 SilcSFTPHandle handle,
505 SilcSFTPDataCallback callback,
508 /****f* silcsftp/SilcSFTPAPI/silc_sftp_write
512 * void silc_sftp_write(SilcSFTP sftp,
513 * SilcSFTPHandle handle,
515 * const unsigned char *data,
516 * SilcUInt32 data_len,
517 * SilcSFTPStatusCallback callback,
522 * Writes to a file indicated by the file handle `handle' starting from
523 * offset of `offset' at most `data_len' bytes of `data'. The `callback'
524 * is called to indicate the status of the writing.
527 void silc_sftp_write(SilcSFTP sftp,
528 SilcSFTPHandle handle,
530 const unsigned char *data,
532 SilcSFTPStatusCallback callback,
535 /****f* silcsftp/SilcSFTPAPI/silc_sftp_remove
539 * void silc_sftp_remove(SilcSFTP sftp,
540 * const char *filename,
541 * SilcSFTPStatusCallback callback,
546 * Removes a file indicated by the `filename'. Calls the `callback'
547 * to indicate the status of the removing.
550 void silc_sftp_remove(SilcSFTP sftp,
551 const char *filename,
552 SilcSFTPStatusCallback callback,
555 /****f* silcsftp/SilcSFTPAPI/silc_sftp_rename
559 * void silc_sftp_rename(SilcSFTP sftp,
560 * const char *oldname,
561 * const char *newname,
562 * SilcSFTPStatusCallback callback,
567 * Renames a file indicated by the `oldname' to the name `newname'. The
568 * `callback' is called to indicate the status of the renaming.
571 void silc_sftp_rename(SilcSFTP sftp,
574 SilcSFTPStatusCallback callback,
577 /****f* silcsftp/SilcSFTPAPI/silc_sftp_mkdir
581 * void silc_sftp_mkdir(SilcSFTP sftp,
583 * SilcSFTPAttributes attrs,
584 * SilcSFTPStatusCallback callback,
589 * Creates a new directory indicated by the `path' with attributes indicated
590 * by the `attrs'. The `callback' is called to indicate the status of the
594 void silc_sftp_mkdir(SilcSFTP sftp,
596 SilcSFTPAttributes attrs,
597 SilcSFTPStatusCallback callback,
600 /****f* silcsftp/SilcSFTPAPI/silc_sftp_rmdir
604 * void silc_sftp_rmdir(SilcSFTP sftp,
606 * SilcSFTPStatusCallback callback,
611 * Removes a directory indicated by the `path' and calls the `callback'
612 * to indicate the status of the removal.
615 void silc_sftp_rmdir(SilcSFTP sftp,
617 SilcSFTPStatusCallback callback,
620 /****f* silcsftp/SilcSFTPAPI/silc_sftp_opendir
624 * void silc_sftp_opendir(SilcSFTP sftp,
626 * SilcSFTPHandleCallback callback,
631 * Opens a directory indicated by the `path'. The `callback' is called
632 * to return the opened file handle.
635 void silc_sftp_opendir(SilcSFTP sftp,
637 SilcSFTPHandleCallback callback,
640 /****f* silcsftp/SilcSFTPAPI/silc_sftp_readdir
644 * void silc_sftp_readdir(SilcSFTP sftp,
645 * SilcSFTPHandle handle,
646 * SilcSFTPNameCallback callback,
651 * Reads the contents of the directory indicated by the `handle' and
652 * calls the `callback' to return the read file(s) from the directory.
655 void silc_sftp_readdir(SilcSFTP sftp,
656 SilcSFTPHandle handle,
657 SilcSFTPNameCallback callback,
660 /****f* silcsftp/SilcSFTPAPI/silc_sftp_stat
664 * void silc_sftp_stat(SilcSFTP sftp,
666 * SilcSFTPAttrCallback callback,
671 * Gets the file attributes for a file indicated by the `path'. This
672 * will follow symbolic links also. Calls the `callback' to return the
676 void silc_sftp_stat(SilcSFTP sftp,
678 SilcSFTPAttrCallback callback,
681 /****f* silcsftp/SilcSFTPAPI/silc_sftp_lstat
685 * void silc_sftp_lstat(SilcSFTP sftp,
687 * SilcSFTPAttrCallback callback,
692 * Gets the file attributes for a file indicated by the `path'. This
693 * will not follow symbolic links. Calls the `callback' to return the
697 void silc_sftp_lstat(SilcSFTP sftp,
699 SilcSFTPAttrCallback callback,
702 /****f* silcsftp/SilcSFTPAPI/silc_sftp_fstat
706 * void silc_sftp_fstat(SilcSFTP fstp,
707 * SilcSFTPHandle handle,
708 * SilcSFTPAttrCallback callback,
713 * Gets a file attributes for a opened file indicated by the `handle'.
714 * Calls the `callback' to return the file attributes.
717 void silc_sftp_fstat(SilcSFTP fstp,
718 SilcSFTPHandle handle,
719 SilcSFTPAttrCallback callback,
722 /****f* silcsftp/SilcSFTPAPI/silc_sftp_setstat
726 * void silc_sftp_setstat(SilcSFTP sftp,
728 * SilcSFTPAttributes attrs,
729 * SilcSFTPStatusCallback callback,
734 * Sets a file attributes to a file indicated by the `path' with the
735 * attributes indicated by the `attrs'. Calls the `callback' to indicate
736 * the status of the setting.
739 void silc_sftp_setstat(SilcSFTP sftp,
741 SilcSFTPAttributes attrs,
742 SilcSFTPStatusCallback callback,
745 /****f* silcsftp/SilcSFTPAPI/silc_sftp_fsetstat
749 * void silc_sftp_fsetstat(SilcSFTP sftp,
750 * SilcSFTPHandle handle,
751 * SilcSFTPAttributes attrs,
752 * SilcSFTPStatusCallback callback,
757 * Sets a file attributes to a opened file indicated by the `handle' with
758 * the attributes indicated by the `attrs'. Calls the `callback' to
759 * indicate the status of the setting.
762 void silc_sftp_fsetstat(SilcSFTP sftp,
763 SilcSFTPHandle handle,
764 SilcSFTPAttributes attrs,
765 SilcSFTPStatusCallback callback,
768 /****f* silcsftp/SilcSFTPAPI/silc_sftp_readlink
772 * void silc_sftp_readlink(SilcSFTP sftp,
774 * SilcSFTPNameCallback callback,
779 * Reads the target of a symbolic link indicated by the `path'. The
780 * `callback' is called to return the target of the symbolic link.
783 void silc_sftp_readlink(SilcSFTP sftp,
785 SilcSFTPNameCallback callback,
788 /****f* silcsftp/SilcSFTPAPI/silc_sftp_symlink
792 * void silc_sftp_symlink(SilcSFTP sftp,
793 * const char *linkpath,
794 * const char *targetpath,
795 * SilcSFTPStatusCallback callback,
800 * Creates a new symbolic link indicated by the `linkpath' to the target
801 * indicated by the `targetpath'. The `callback' is called to indicate
802 * the status of creation.
805 void silc_sftp_symlink(SilcSFTP sftp,
806 const char *linkpath,
807 const char *targetpath,
808 SilcSFTPStatusCallback callback,
811 /****f* silcsftp/SilcSFTPAPI/silc_sftp_realpath
815 * void silc_sftp_realpath(SilcSFTP sftp,
817 * SilcSFTPNameCallback callback,
822 * Canonicalizes the path indicated by the `path' to a absolute path.
823 * The `callback' is called to return the absolute path.
826 void silc_sftp_realpath(SilcSFTP sftp,
828 SilcSFTPNameCallback callback,
831 /****f* silcsftp/SilcSFTPAPI/silc_sftp_extended
835 * void silc_sftp_extended(SilcSFTP sftp,
836 * const char *request,
837 * const unsigned char *data,
838 * SilcUInt32 data_len,
839 * SilcSFTPExtendedCallback callback,
844 * Performs an extended operation indicated by the `request' with
845 * optional extended operation data indicated by the `data'. The callback
846 * is called to return any data associated with the extended request.
849 void silc_sftp_extended(SilcSFTP sftp,
851 const unsigned char *data,
853 SilcSFTPExtendedCallback callback,
857 /* SFTP Server Interface */
859 #include "silcsftp_fs.h"
861 /****f* silcsftp/SilcSFTPAPI/silc_sftp_server_start
865 * SilcSFTP silc_sftp_server_start(SilcStream stream,
866 * SilcSchedule schedule,
867 * SilcSFTPErrorCallback error_cb,
869 * SilcSFTPFilesystem fs);
873 * Starts SFTP server and returns a context to it. This function returns
874 * the allocated SFTP server context or NULL on error. The `stream' is
875 * the stream (connection) to the client. The `error_cb' will be called
876 * when the `stream' is ended (SILC_SFTP_STATUS_EOF). The caller is
877 * responsible of closing and destroying the `stream'. The `fs' is the
878 * filesystem context allocated by the application.
880 * If `schedule' is NULL this will call silc_schedule_get_global to try to
881 * get global scheduler.
884 SilcSFTP silc_sftp_server_start(SilcStream stream,
885 SilcSchedule schedule,
886 SilcSFTPErrorCallback error_cb,
888 SilcSFTPFilesystem fs);
890 /****f* silcsftp/SilcSFTPAPI/silc_sftp_server_shutdown
894 * void silc_sftp_server_shutdown(SilcSFTP sftp);
898 * Shutdown the SFTP server. The caller is responsible of closing the
899 * associated stream. The SFTP context is freed and is invalid after
900 * this function returns.
903 void silc_sftp_server_shutdown(SilcSFTP sftp);
905 /****d* silcsftp/SilcSFTPAPI/SilcSFTPMonitors
909 * typedef enum { ... } SilcSFTPMonitors;
913 * SFTP server monitor types. These can be masked together to monitor
914 * various client requests.
919 SILC_SFTP_MONITOR_INIT = 0x0001,
920 SILC_SFTP_MONITOR_OPEN = 0x0002,
921 SILC_SFTP_MONITOR_CLOSE = 0x0004,
922 SILC_SFTP_MONITOR_READ = 0x0008,
923 SILC_SFTP_MONITOR_WRITE = 0x0010,
924 SILC_SFTP_MONITOR_REMOVE = 0x0020,
925 SILC_SFTP_MONITOR_RENAME = 0x0040,
926 SILC_SFTP_MONITOR_MKDIR = 0x0080,
927 SILC_SFTP_MONITOR_RMDIR = 0x0100,
928 SILC_SFTP_MONITOR_OPENDIR = 0x0200,
929 SILC_SFTP_MONITOR_READDIR = 0x0400,
930 SILC_SFTP_MONITOR_STAT = 0x0800,
931 SILC_SFTP_MONITOR_LSTAT = 0x1000,
932 SILC_SFTP_MONITOR_FSTAT = 0x2000,
933 SILC_SFTP_MONITOR_SETSTAT = 0x4000,
934 SILC_SFTP_MONITOR_FSETSTAT = 0x8000,
935 SILC_SFTP_MONITOR_READLINK = 0x10000,
936 SILC_SFTP_MONITOR_SYMLINK = 0x20000,
937 SILC_SFTP_MONITOR_REALPATH = 0x40000,
938 SILC_SFTP_MONITOR_EXTENDED = 0x80000,
942 /****s* silcsftp/SilcSFTPAPI/SilcSFTPMonitorData
946 * typedef struct { ... } *SilcSFTPMonitorData, SilcSFTPMonitorDataStruct;
950 * This structure includes the monitor type specific data. The
951 * application can check what the client has requested from this
952 * structure. See the comments below what data is available for what
957 typedef struct SilcSFTPMonitorDataObject {
958 SilcSFTPVersion version; /* _INIT */
959 char *name; /* _OPEN, _REMOVE, _RENAME, _MKDIR,
960 _RMDIR, _OPENDIR, _STAT, _LSTAT,
961 _SETSTAT, _READLINK, _SYMLINK, _REALPATH */
962 char *name2; /* _RENAME, _SYMLINK */
963 SilcSFTPFileOperation pflags; /* _OPEN */
964 SilcUInt64 offset; /* _READ, _WRITE */
965 SilcUInt32 data_len; /* _READ, _WRITE */
966 SilcSFTPName names; /* _READDIR, _READLINK, _REALPATH */
967 } *SilcSFTPMonitorData, SilcSFTPMonitorDataStruct;
970 /****f* silcsftp/SilcSFTPAPI/SilcSFTPMonitor
974 * typedef void (*SilcSFTPMonitor)(SilcSFTP sftp
975 * SilcSFTPMonitors type,
976 * const SilcSFTPMonitorData data,
981 * Monitor callback that is called when an specified request is
982 * received from client. The `type' is the requested type that
983 * was being monitored.
986 typedef void (*SilcSFTPMonitor)(SilcSFTP sftp,
987 SilcSFTPMonitors type,
988 const SilcSFTPMonitorData data,
991 /****f* silcsftp/SilcSFTPAPI/silc_sftp_server_set_monitor
995 * void silc_sftp_server_set_monitor(SilcSFTP sftp,
996 * SilcSFTPMonitors monitors,
997 * SilcSFTPMonitor monitor,
1002 * Sets monitor callback to monitor various request sent by a client.
1003 * When request that has been set in the `monitors' is received the
1004 * monitor callback will be called to notify the caller.
1007 void silc_sftp_server_set_monitor(SilcSFTP sftp,
1008 SilcSFTPMonitors monitors,
1009 SilcSFTPMonitor monitor,
1012 #endif /* SILCSFTP_H */