Low-level bindings

The symbols documented on this page have all been generated automatically, along with their documentation. Most of them are pure wrappers around the C functions, but some of them also do things like return-type conversion to a Julia type (e.g. converting const char* to String).

Where possible the original documentation from the libssh headers has been included or a link generated to the upstream documentation. Note that some links may not work if the upstream documentation and this page have been generated against different versions, and some symbols in the Other section should be elsewhere.

Warning

The symbols on this page, including the auto-generated wrappers, are unsafe. Improper use may cause memory corruption (including segfaults) and weeping and gnashing of teeth. Check the upstream documentation carefully when using them, and test your code thoroughly.


Authentication

Buffers

Callbacks

LibSSH.lib.ssh_add_channel_callbacksMethod
ssh_add_channel_callbacks(channel, cb)

Add channel callback functions

This function will add channel callback functions to the channel callback list. Callbacks missing from a callback structure will be probed in the next on the list.

Arguments

  • channel: The channel to set the callback structure.
  • cb: The callback structure itself.

Returns

SSH_OK on success, SSH_ERROR on error.

See also

ssh_set_channel_callbacks

source
LibSSH.lib.ssh_set_callbacksMethod
ssh_set_callbacks(session, cb)

Set the session callback functions.

This functions sets the callback structure to use your own callback functions for auth, logging and status.

Note, that the callback structure is not copied into the session so it needs to be valid for the whole session lifetime.

 struct ssh_callbacks_struct cb = {
   .userdata = data,
   .auth_function = my_auth_function
 };
 ssh_callbacks_init(&cb);
 ssh_set_callbacks(session, &cb);

Arguments

  • session: The session to set the callback structure.
  • cb: The callback structure itself.

Returns

SSH_OK on success, SSH_ERROR on error.

source
LibSSH.lib.ssh_set_channel_callbacksMethod
ssh_set_channel_callbacks(channel, cb)

Set the channel callback functions.

This functions sets the callback structure to use your own callback functions for channel data and exceptions.

Note, that the structure is not copied to the channel structure so it needs to be valid as for the whole life of the channel or until it is removed with ssh_remove_channel_callbacks().

 struct ssh_channel_callbacks_struct cb = {
   .userdata = data,
   .channel_data_function = my_channel_data_function
 };
 ssh_callbacks_init(&cb);
 ssh_set_channel_callbacks(channel, &cb);
Warning

this function will not replace existing callbacks but set the new one atop of them.

Arguments

  • channel: The channel to set the callback structure.
  • cb: The callback structure itself.

Returns

SSH_OK on success, SSH_ERROR on error.

source
LibSSH.lib.ssh_set_server_callbacksMethod
ssh_set_server_callbacks(session, cb)

Set the session server callback functions.

This functions sets the callback structure to use your own callback functions for user authentication, new channels and requests.

Note, that the structure is not copied to the session structure so it needs to be valid for the whole session lifetime.

 struct ssh_server_callbacks_struct cb = {
   .userdata = data,
   .auth_password_function = my_auth_function
 };
 ssh_callbacks_init(&cb);
 ssh_set_server_callbacks(session, &cb);

Arguments

  • session: The session to set the callback structure.
  • cb: The callback structure itself.

Returns

SSH_OK on success, SSH_ERROR on error.

source

Channel

Errors

Helpers

Logging

Message

Polling

Public/private keys

Server

LibSSH.lib.ssh_bind_acceptMethod
ssh_bind_accept(ssh_bind_o, session)

Accept an incoming ssh connection and initialize the session.

Arguments

  • ssh_bind_o: The ssh server bind to accept a connection.
  • session: A preallocated ssh session

Returns

SSH_OK when a connection is established

See also

ssh_new

source
LibSSH.lib.ssh_bind_accept_fdMethod
ssh_bind_accept_fd(ssh_bind_o, session, fd)

Accept an incoming ssh connection on the given file descriptor and initialize the session.

Arguments

  • ssh_bind_o: The ssh server bind to accept a connection.
  • session: A preallocated ssh session
  • fd: A file descriptor of an already established TCP inbound connection

Returns

SSH_OK when a connection is established

See also

ssh_new, ssh_bind_accept

source
LibSSH.lib.ssh_bind_freeMethod
ssh_bind_free(ssh_bind_o)

Free a ssh servers bind.

Note that this will also free options that have been set on the bind, including keys set with SSH_BIND_OPTIONS_IMPORT_KEY.

Arguments

  • ssh_bind_o: The ssh server bind to free.
source
LibSSH.lib.ssh_bind_get_fdMethod
ssh_bind_get_fd(ssh_bind_o)

Recover the file descriptor from the session.

Arguments

  • ssh_bind_o: The ssh server bind to get the fd from.

Returns

The file descriptor.

source
LibSSH.lib.ssh_bind_listenMethod
ssh_bind_listen(ssh_bind_o)

Start listening to the socket.

Arguments

  • ssh_bind_o: The ssh server bind to use.

Returns

0 on success, < 0 on error.

source
LibSSH.lib.ssh_bind_set_blockingMethod
ssh_bind_set_blocking(ssh_bind_o, blocking)

Set the session to blocking/nonblocking mode.

Arguments

  • ssh_bind_o: The ssh server bind to use.
  • blocking: Zero for nonblocking mode.
source
LibSSH.lib.ssh_bind_set_callbacksMethod
ssh_bind_set_callbacks(sshbind, callbacks, userdata)

Set the callback for this bind.

     struct ssh_callbacks_struct cb = {
         .userdata = data,
         .auth_function = my_auth_function
     };
     ssh_callbacks_init(&cb);
     ssh_bind_set_callbacks(session, &cb);

Arguments

  • sshbind:[in] The bind to set the callback on.
  • callbacks:[in] An already set up ssh_bind_callbacks instance.
  • userdata:[in] A pointer to private data to pass to the callbacks.

Returns

SSH_OK on success, SSH_ERROR if an error occurred.

source
LibSSH.lib.ssh_bind_set_fdMethod
ssh_bind_set_fd(ssh_bind_o, fd)

Set the file descriptor for a session.

Arguments

  • ssh_bind_o: The ssh server bind to set the fd.
  • fd: The file descriptssh_bind B
source
LibSSH.lib.ssh_message_auth_passwordMethod
ssh_message_auth_password(msg; throw = true)

Auto-generated wrapper around ssh_message_auth_password(). Original upstream documentation is below.


Get the password of the authenticated user.

Deprecated

This function should not be used anymore as there is a callback based server implementation now auth_password_function.

Arguments

  • msg:[in] The message to get the password from.

Returns

The password or NULL if an error occurred.

See also

ssh_message_get(), ssh_message_type()

source
LibSSH.lib.ssh_message_auth_pubkeyMethod
ssh_message_auth_pubkey(msg)

Get the publickey of the authenticated user.

If you need the key for later user you should duplicate it.

Deprecated

This function should not be used anymore as there is a callback based server implementation auth_pubkey_function.

Arguments

  • msg:[in] The message to get the public key from.

Returns

The public key or NULL.

See also

ssh_key_dup(), ssh_key_cmp(), ssh_message_get(), ssh_message_type()

source
LibSSH.lib.ssh_message_auth_publickey_stateMethod
ssh_message_auth_publickey_state(msg)
Deprecated

This function should not be used anymore as there is a callback based server implementation auth_pubkey_function

Arguments

  • msg:[in] The message to get the public key state from.
source
LibSSH.lib.ssh_message_auth_userMethod
ssh_message_auth_user(msg; throw = true)

Auto-generated wrapper around ssh_message_auth_user(). Original upstream documentation is below.


Get the name of the authenticated user.

Arguments

  • msg:[in] The message to get the username from.

Returns

The username or NULL if an error occurred.

See also

ssh_message_get(), ssh_message_type()

source
LibSSH.lib.ssh_message_reply_defaultMethod
ssh_message_reply_default(msg; throw = true)

Auto-generated wrapper around ssh_message_reply_default(). Original upstream documentation is below.


Reply with a standard reject message.

Use this function if you don't know what to respond or if you want to reject a request.

Arguments

  • msg:[in] The message to use for the reply.

Returns

0 on success, -1 on error.

See also

ssh_message_get()

source
LibSSH.lib.ssh_server_init_kexMethod
ssh_server_init_kex(session)

Initialize the set of key exchange, hostkey, ciphers, MACs, and compression algorithms for the given ssh_session.

The selection of algorithms and keys used are determined by the options that are currently set in the given ssh_session structure. May only be called before the initial key exchange has begun.

Arguments

  • session: The session structure to initialize.

Returns

SSH_OK if initialization succeeds.

See also

ssh_handle_key_exchange, ssh_options_set

source

Session

Strings

SCP

SFTP

LibSSH.lib.sftp_aio_begin_readMethod
sftp_aio_begin_read(file, len, aio)

Start an asynchronous read from a file using an opened sftp file handle.

Its goal is to avoid the slowdowns related to the request/response pattern of a synchronous read. To do so, you must call 2 functions :

sftp_aio_begin_read() and sftp_aio_wait_read().

  • The first step is to call sftp_aio_begin_read(). This function sends a read request to the sftp server, dynamically allocates memory to store information about the sent request and provides the caller an sftp aio handle to that memory.

  • The second step is to call sftp_aio_wait_read() and pass it the address of a location storing the sftp aio handle provided by sftp_aio_begin_read().

These two functions do not close the open sftp file handle passed to sftp_aio_begin_read() irrespective of whether they fail or not.

It is the responsibility of the caller to ensure that the open sftp file handle passed to sftp_aio_begin_read() must not be closed before the corresponding call to sftp_aio_wait_read(). After sftp_aio_wait_read() returns, it is caller's decision whether to immediately close the file by calling sftp_close() or to keep it open and perform some more operations on it.

This function caps the length a user is allowed to read from an sftp file, the value of len parameter after capping is returned on success.

The value used for the cap is same as the value of the max_read_length field of the sftp_limits_t returned by sftp_limits().

Warning

When calling this function, the internal file offset is updated corresponding to the number of bytes requested to read.

Warning

A call to sftp_aio_begin_read() sends a request to the server. When the server answers, libssh allocates memory to store it until sftp_aio_wait_read() is called. Not calling sftp_aio_wait_read() will lead to memory leaks.

Arguments

  • file: The opened sftp file handle to be read from.
  • len: Number of bytes to read.
  • aio: Pointer to a location where the sftp aio handle (corresponding to the sent request) should be stored.

Returns

On success, the number of bytes the server is requested to read (value of len parameter after capping). On error, SSH_ERROR with sftp and ssh errors set.

See also

sftp_aio_wait_read(), sftp_aio_free(), sftp_open(), sftp_close(), sftp_get_error(), ssh_get_error()

source
LibSSH.lib.sftp_aio_begin_writeMethod
sftp_aio_begin_write(file, buf, len, aio)

Start an asynchronous write to a file using an opened sftp file handle.

Its goal is to avoid the slowdowns related to the request/response pattern of a synchronous write. To do so, you must call 2 functions :

sftp_aio_begin_write() and sftp_aio_wait_write().

  • The first step is to call sftp_aio_begin_write(). This function sends a write request to the sftp server, dynamically allocates memory to store information about the sent request and provides the caller an sftp aio handle to that memory.

  • The second step is to call sftp_aio_wait_write() and pass it the address of a location storing the sftp aio handle provided by sftp_aio_begin_write().

These two functions do not close the open sftp file handle passed to sftp_aio_begin_write() irrespective of whether they fail or not.

It is the responsibility of the caller to ensure that the open sftp file handle passed to sftp_aio_begin_write() must not be closed before the corresponding call to sftp_aio_wait_write(). After sftp_aio_wait_write() returns, it is caller's decision whether to immediately close the file by calling sftp_close() or to keep it open and perform some more operations on it.

This function caps the length a user is allowed to write to an sftp file, the value of len parameter after capping is returned on success.

The value used for the cap is same as the value of the max_write_length field of the sftp_limits_t returned by sftp_limits().

Warning

When calling this function, the internal file offset is updated corresponding to the number of bytes requested to write.

Warning

A call to sftp_aio_begin_write() sends a request to the server. When the server answers, libssh allocates memory to store it until sftp_aio_wait_write() is called. Not calling sftp_aio_wait_write() will lead to memory leaks.

Arguments

  • file: The opened sftp file handle to write to.
  • buf: Pointer to the buffer containing data to write.
  • len: Number of bytes to write.
  • aio: Pointer to a location where the sftp aio handle (corresponding to the sent request) should be stored.

Returns

On success, the number of bytes the server is requested to write (value of len parameter after capping). On error, SSH_ERROR with sftp and ssh errors set.

See also

sftp_aio_wait_write(), sftp_aio_free(), sftp_open(), sftp_close(), sftp_get_error(), ssh_get_error()

source
LibSSH.lib.sftp_aio_freeMethod
sftp_aio_free(aio)

Deallocate memory corresponding to a sftp aio handle.

This function deallocates memory corresponding to the aio handle returned by the sftp_aio_begin_*() functions. Users can use this function to free memory corresponding to an aio handle for an outstanding async i/o request on encountering some error.

Arguments

  • aio: sftp aio handle corresponding to which memory has to be deallocated.

See also

sftp_aio_begin_read(), sftp_aio_wait_read(), sftp_aio_begin_write(), sftp_aio_wait_write()

source
LibSSH.lib.sftp_aio_wait_readMethod
sftp_aio_wait_read(aio::Ptr{sftp_aio}, buf::Ptr{Cvoid}, buf_size::Csize_t)

Auto-generated wrapper around sftp_aio_wait_read(). Original upstream documentation is below.


Wait for an asynchronous read to complete and store the read data in the supplied buffer.

A pointer to an sftp aio handle should be passed while calling this function. Except when the return value is SSH_AGAIN, this function releases the memory corresponding to the supplied aio handle and assigns NULL to that aio handle using the passed pointer to that handle.

If the file is opened in non-blocking mode and the request hasn't been executed yet, this function returns SSH_AGAIN and must be called again using the same sftp aio handle.

Warning

A call to this function with an invalid sftp aio handle may never return.

Arguments

  • aio: Pointer to the sftp aio handle returned by sftp_aio_begin_read().
  • buf: Pointer to the buffer in which read data will be stored.
  • buf_size: Size of the buffer in bytes. It should be bigger or equal to the length parameter of the sftp_aio_begin_read() call.

Returns

Number of bytes read, 0 on EOF, SSH_ERROR if an error occurred, SSH_AGAIN if the file is opened in nonblocking mode and the request hasn't been executed yet.

See also

sftp_aio_begin_read(), sftp_aio_free()

source
LibSSH.lib.sftp_aio_wait_writeMethod
sftp_aio_wait_write(aio::Ptr{sftp_aio})

Auto-generated wrapper around sftp_aio_wait_write(). Original upstream documentation is below.


Wait for an asynchronous write to complete.

A pointer to an sftp aio handle should be passed while calling this function. Except when the return value is SSH_AGAIN, this function releases the memory corresponding to the supplied aio handle and assigns NULL to that aio handle using the passed pointer to that handle.

If the file is opened in non-blocking mode and the request hasn't been executed yet, this function returns SSH_AGAIN and must be called again using the same sftp aio handle.

Warning

A call to this function with an invalid sftp aio handle may never return.

Arguments

Returns

Number of bytes written on success, SSH_ERROR if an error occurred, SSH_AGAIN if the file is opened in nonblocking mode and the request hasn't been executed yet.

See also

sftp_aio_begin_write(), sftp_aio_free()

source
LibSSH.lib.sftp_async_readMethod
sftp_async_read(file, data, len, id)

Wait for an asynchronous read to complete and save the data.

Warning

A call to this function with an invalid identifier will never return.

Arguments

  • file: The opened sftp file handle to be read from.
  • data: Pointer to buffer to receive read data.
  • len: Size of the buffer in bytes. It should be bigger or equal to the length parameter of the sftp_async_read_begin() call.
  • id: The identifier returned by the sftp_async_read_begin() function.

Returns

Number of bytes read, 0 on EOF, SSH_ERROR if an error occurred, SSH_AGAIN if the file is opened in nonblocking mode and the request hasn't been executed yet.

See also

sftp_async_read_begin()

source
LibSSH.lib.sftp_async_read_beginMethod
sftp_async_read_begin(file, len)

Start an asynchronous read from a file using an opened sftp file handle.

Its goal is to avoid the slowdowns related to the request/response pattern of a synchronous read. To do so, you must call 2 functions:

sftp_async_read_begin() and sftp_async_read().

The first step is to call sftp_async_read_begin(). This function returns a request identifier. The second step is to call sftp_async_read() using the returned identifier.

Warning

When calling this function, the internal offset is updated corresponding to the len parameter.

Warning

A call to sftp_async_read_begin() sends a request to the server. When the server answers, libssh allocates memory to store it until sftp_async_read() is called. Not calling sftp_async_read() will lead to memory leaks.

Arguments

  • file: The opened sftp file handle to be read from.
  • len: Size to read in bytes.

Returns

An identifier corresponding to the sent request, < 0 on error.

See also

sftp_async_read(), sftp_open()

source
LibSSH.lib.sftp_canonicalize_pathMethod
sftp_canonicalize_path(sftp, path)

Canonicalize a sftp path.

Arguments

  • sftp: The sftp session handle.
  • path: The path to be canonicalized.

Returns

A pointer to the newly allocated canonicalized path, NULL on error. The caller needs to free the memory using ssh_string_free_char().

source
LibSSH.lib.sftp_chmodMethod
sftp_chmod(sftp, file, mode)

Change permissions of a file

Arguments

  • sftp: The sftp session handle.
  • file: The file which owner and group should be changed.
  • mode: Specifies the permissions to use. It is modified by the process's umask in the usual way: The permissions of the created file are (mode & ~umask)

Returns

0 on success, < 0 on error with ssh and sftp error set.

See also

sftp_get_error()

source
LibSSH.lib.sftp_chownMethod
sftp_chown(sftp, file, owner, group)

Change the file owner and group

Arguments

  • sftp: The sftp session handle.
  • file: The file which owner and group should be changed.
  • owner: The new owner which should be set.
  • group: The new group which should be set.

Returns

0 on success, < 0 on error with ssh and sftp error set.

See also

sftp_get_error()

source
LibSSH.lib.sftp_closeMethod
sftp_close(file::sftp_file)

Auto-generated wrapper around sftp_close(). Original upstream documentation is below.


Close an open file handle.

Arguments

  • file: The open sftp file handle to close.

Returns

Returns SSH_NO_ERROR or SSH_ERROR if an error occurred.

See also

sftp_open()

source
LibSSH.lib.sftp_closedirMethod
sftp_closedir(dir::sftp_dir)

Auto-generated wrapper around sftp_closedir(). Original upstream documentation is below.


Close a directory handle opened by sftp_opendir().

Arguments

  • dir: The sftp directory handle to close.

Returns

Returns SSH_NO_ERROR or SSH_ERROR if an error occurred.

source
LibSSH.lib.sftp_dir_eofMethod
sftp_dir_eof(dir)

Tell if the directory has reached EOF (End Of File).

Arguments

  • dir: The sftp directory handle.

Returns

1 if the directory is EOF, 0 if not.

See also

sftp_readdir()

source
LibSSH.lib.sftp_expand_pathMethod
sftp_expand_path(sftp, path)

Canonicalize path using expand-path.com extension

Arguments

  • sftp: The sftp session handle.
  • path: The path to be canonicalized.

Returns

A pointer to the newly allocated canonicalized path, NULL on error. The caller needs to free the memory using ssh_string_free_char().

source
LibSSH.lib.sftp_extension_supportedMethod
sftp_extension_supported(sftp, name, data)

Check if the given extension is supported.

Example:

 sftp_extension_supported(sftp, "statvfs@openssh.com", "2");

Arguments

  • sftp: The sftp session to use.
  • name: The name of the extension.
  • data: The data of the extension.

Returns

1 if supported, 0 if not.

source
LibSSH.lib.sftp_extensions_get_countMethod
sftp_extensions_get_count(sftp)

Get the count of extensions provided by the server.

Arguments

  • sftp: The sftp session to use.

Returns

The count of extensions provided by the server, 0 on error or not available.

source
LibSSH.lib.sftp_extensions_get_dataMethod
sftp_extensions_get_data(sftp, indexn; throw = true)

Auto-generated wrapper around sftp_extensions_get_data(). Original upstream documentation is below.


Get the data of the extension provided by the server.

This is normally the version number of the extension.

Arguments

  • sftp: The sftp session to use.
  • indexn: The index number of the extension data you want.

Returns

The data of the extension.

source
LibSSH.lib.sftp_extensions_get_nameMethod
sftp_extensions_get_name(sftp, indexn; throw = true)

Auto-generated wrapper around sftp_extensions_get_name(). Original upstream documentation is below.


Get the name of the extension provided by the server.

Arguments

  • sftp: The sftp session to use.
  • indexn: The index number of the extension name you want.

Returns

The name of the extension.

source
LibSSH.lib.sftp_freeMethod
sftp_free(sftp)

Close and deallocate a sftp session.

Arguments

  • sftp: The sftp session handle to free.
source
LibSSH.lib.sftp_fstatMethod
sftp_fstat(file)

Get information about a file or directory from a file handle.

Arguments

  • file: The sftp file handle to get the stat information.

Returns

The sftp attributes structure of the file or directory, NULL on error with ssh and sftp error set.

See also

sftp_get_error()

source
LibSSH.lib.sftp_fsyncMethod
sftp_fsync(file)

Synchronize a file's in-core state with storage device

This calls the "fsync@openssh.com" extension. You should check if the extensions is supported using:

 int supported = sftp_extension_supported(sftp, "fsync@openssh.com", "1");

Arguments

  • file: The opened sftp file handle to sync

Returns

0 on success, < 0 on error with ssh and sftp error set.

source
LibSSH.lib.sftp_get_errorMethod
sftp_get_error(sftp)

Get the last sftp error.

Use this function to get the latest error set by a posix like sftp function.

Arguments

  • sftp: The sftp session where the error is saved.

Returns

The saved error (see server responses), < 0 if an error in the function occurred.

See also

Server responses

source
LibSSH.lib.sftp_hardlinkMethod
sftp_hardlink(sftp, oldpath, newpath)

Create a hard link.

Arguments

  • sftp: The sftp session handle.
  • oldpath: Specifies the pathname of the file for which the new hardlink is to be created.
  • newpath: Specifies the pathname of the hardlink to be created.

Returns

0 on success, -1 on error with ssh and sftp error set.

See also

sftp_get_error()

source
LibSSH.lib.sftp_home_directoryMethod
sftp_home_directory(sftp::sftp_session, username::Ptr{Cchar})

Auto-generated wrapper around sftp_home_directory(). Original upstream documentation is below.


Get the specified user's home directory

This calls the "home-directory" extension. You should check if the extension is supported using:

 int supported  = sftp_extension_supported(sftp, "home-directory", "1");

Arguments

  • sftp: The sftp session handle.
  • username: username of the user whose home directory is requested.

Returns

On success, a newly allocated string containing the absolute real-path of the home directory of the user. NULL on error. The caller needs to free the memory using ssh_string_free_char().

source
LibSSH.lib.sftp_initMethod
sftp_init(sftp::sftp_session)

Auto-generated wrapper around sftp_init(). Original upstream documentation is below.


Initialize the sftp protocol with the server.

This function involves the SFTP protocol initialization (as described in the SFTP specification), including the version and extensions negotiation.

Arguments

  • sftp: The sftp session to initialize.

Returns

0 on success, < 0 on error with ssh error set.

See also

sftp_new()

source
LibSSH.lib.sftp_limitsMethod
sftp_limits(sftp)

Get information about the various limits the server might impose.

Arguments

  • sftp: The sftp session handle.

Returns

A limits structure or NULL on error.

See also

sftp_get_error()

source
LibSSH.lib.sftp_lsetstatMethod
sftp_lsetstat(sftp, file, attr)

This request is like setstat (excluding mode and size) but sets file attributes on symlinks themselves.

Note, that this function can only set time values using 32 bit values due to the restrictions in the SFTP protocol version 3 implemented by libssh. The support for 64 bit time values was introduced in SFTP version 5, which is not implemented by libssh nor any major SFTP servers.

Arguments

  • sftp: The sftp session handle.
  • file: The symbolic link which attributes should be changed.
  • attr: The file attributes structure with the attributes set which should be changed.

Returns

0 on success, < 0 on error with ssh and sftp error set.

See also

sftp_get_error()

source
LibSSH.lib.sftp_lstatMethod
sftp_lstat(session, path)

Get information about a file or directory.

Identical to sftp_stat, but if the file or directory is a symbolic link, then the link itself is stated, not the file that it refers to.

Arguments

  • session: The sftp session handle.
  • path: The path to the file or directory to obtain the information.

Returns

The sftp attributes structure of the file or directory, NULL on error with ssh and sftp error set.

See also

sftp_get_error()

source
LibSSH.lib.sftp_mkdirMethod
sftp_mkdir(sftp::sftp_session, directory::Ptr{Cchar}, mode::mode_t)

Auto-generated wrapper around sftp_mkdir(). Original upstream documentation is below.


Create a directory.

Arguments

  • sftp: The sftp session handle.
  • directory: The directory to create.
  • mode: Specifies the permissions to use. It is modified by the process's umask in the usual way: The permissions of the created file are (mode & ~umask)

Returns

0 on success, < 0 on error with ssh and sftp error set.

See also

sftp_get_error()

source
LibSSH.lib.sftp_newMethod
sftp_new(session::ssh_session)

Auto-generated wrapper around sftp_new(). Original upstream documentation is below.


Creates a new sftp session.

This function creates a new sftp session and allocates a new sftp channel with the server inside of the provided ssh session. This function call is usually followed by the sftp_init(), which initializes SFTP protocol itself.

Arguments

  • session: The ssh session to use.

Returns

A new sftp session or NULL on error.

See also

sftp_free(), sftp_init()

source
LibSSH.lib.sftp_new_channelMethod
sftp_new_channel(session, channel)

Start a new sftp session with an existing channel.

Arguments

  • session: The ssh session to use.
  • channel: An open session channel with subsystem already allocated

Returns

A new sftp session or NULL on error.

See also

sftp_free()

source
LibSSH.lib.sftp_openMethod
sftp_open(session::sftp_session, file::Ptr{Cchar}, accesstype::Cint, mode::mode_t)

Auto-generated wrapper around sftp_open(). Original upstream documentation is below.


Open a file on the server.

Arguments

  • session: The sftp session handle.
  • file: The file to be opened.
  • accesstype: Is one of O_RDONLY, O_WRONLY or O_RDWR which request opening the file read-only,write-only or read/write. Acesss may also be bitwise-or'd with one or more of the following: O_CREAT - If the file does not exist it will be created. O_EXCL - When used with O_CREAT, if the file already exists it is an error and the open will fail. O_TRUNC - If the file already exists it will be truncated.
  • mode: Mode specifies the permissions to use if a new file is created. It is modified by the process's umask in the usual way: The permissions of the created file are (mode & ~umask)

Returns

A sftp file handle, NULL on error with ssh and sftp error set.

See also

sftp_get_error()

source
LibSSH.lib.sftp_opendirMethod
sftp_opendir(session::sftp_session, path::Ptr{Cchar})

Auto-generated wrapper around sftp_opendir(). Original upstream documentation is below.


Open a directory used to obtain directory entries.

Arguments

  • session: The sftp session handle to open the directory.
  • path: The path of the directory to open.

Returns

A sftp directory handle or NULL on error with ssh and sftp error set.

See also

sftp_readdir, sftp_closedir

source
LibSSH.lib.sftp_readMethod
sftp_read(file, buf, count)

Read from a file using an opened sftp file handle.

This function caps the length a user is allowed to read from an sftp file.

The value used for the cap is same as the value of the max_read_length field of the sftp_limits_t returned by sftp_limits().

Arguments

  • file: The opened sftp file handle to be read from.
  • buf: Pointer to buffer to receive read data.
  • count: Size of the buffer in bytes.

Returns

Number of bytes read, < 0 on error with ssh and sftp error set.

See also

sftp_get_error()

source
LibSSH.lib.sftp_readdirMethod
sftp_readdir(session::sftp_session, dir::sftp_dir)

Auto-generated wrapper around sftp_readdir(). Original upstream documentation is below.


Get a single file attributes structure of a directory.

Arguments

  • session: The sftp session handle to read the directory entry.
  • dir: The opened sftp directory handle to read from.

Returns

A file attribute structure or NULL at the end of the directory.

See also

sftp_opendir(), sftp_attribute_free(), sftp_closedir()

source
LibSSH.lib.sftp_readlinkMethod
sftp_readlink(sftp, path)

Read the value of a symbolic link.

Arguments

  • sftp: The sftp session handle.
  • path: Specifies the path name of the symlink to be read.

Returns

The target of the link, NULL on error. The caller needs to free the memory using ssh_string_free_char().

See also

sftp_get_error()

source
LibSSH.lib.sftp_renameMethod
sftp_rename(sftp::sftp_session, original::Ptr{Cchar}, newname::Ptr{Cchar})

Auto-generated wrapper around sftp_rename(). Original upstream documentation is below.


Rename or move a file or directory.

Arguments

  • sftp: The sftp session handle.
  • original: The original url (source url) of file or directory to be moved.
  • newname: The new url (destination url) of the file or directory after the move.

Returns

0 on success, < 0 on error with ssh and sftp error set.

See also

sftp_get_error()

source
LibSSH.lib.sftp_rewindMethod
sftp_rewind(file)

Rewinds the position of the file pointer to the beginning of the file.

Arguments

  • file: Open sftp file handle.
source
LibSSH.lib.sftp_rmdirMethod
sftp_rmdir(sftp::sftp_session, directory::Ptr{Cchar})

Auto-generated wrapper around sftp_rmdir(). Original upstream documentation is below.


Remove a directory.

Arguments

  • sftp: The sftp session handle.
  • directory: The directory to remove.

Returns

0 on success, < 0 on error with ssh and sftp error set.

See also

sftp_get_error()

source
LibSSH.lib.sftp_seekMethod
sftp_seek(file, new_offset)

Seek to a specific location in a file.

Arguments

  • file: Open sftp file handle to seek in.
  • new_offset: Offset in bytes to seek.

Returns

0 on success, < 0 on error.

source
LibSSH.lib.sftp_seek64Method
sftp_seek64(file, new_offset)

Seek to a specific location in a file. This is the 64bit version.

Arguments

  • file: Open sftp file handle to seek in.
  • new_offset: Offset in bytes to seek.

Returns

0 on success, < 0 on error.

source
LibSSH.lib.sftp_server_initMethod
sftp_server_init(sftp)

Initialize the sftp server.

Arguments

  • sftp: The sftp session to init.

Returns

0 on success, < 0 on error.

source
LibSSH.lib.sftp_server_newMethod
sftp_server_new(session, chan)

Create a new sftp server session.

Arguments

  • session: The ssh session to use.
  • chan: The ssh channel to use.

Returns

A new sftp server session.

source
LibSSH.lib.sftp_server_versionMethod
sftp_server_version(sftp)

Get the version of the SFTP protocol supported by the server

Arguments

  • sftp: The sftp session handle.

Returns

The server version.

source
LibSSH.lib.sftp_setstatMethod
sftp_setstat(sftp, file, attr)

Set file attributes on a file, directory or symbolic link.

Note, that this function can only set time values using 32 bit values due to the restrictions in the SFTP protocol version 3 implemented by libssh. The support for 64 bit time values was introduced in SFTP version 5, which is not implemented by libssh nor any major SFTP servers.

Arguments

  • sftp: The sftp session handle.
  • file: The file which attributes should be changed.
  • attr: The file attributes structure with the attributes set which should be changed.

Returns

0 on success, < 0 on error with ssh and sftp error set.

See also

sftp_get_error()

source
LibSSH.lib.sftp_statMethod
sftp_stat(session::sftp_session, path::Ptr{Cchar})

Auto-generated wrapper around sftp_stat(). Original upstream documentation is below.


Get information about a file or directory.

Arguments

  • session: The sftp session handle.
  • path: The path to the file or directory to obtain the information.

Returns

The sftp attributes structure of the file or directory, NULL on error with ssh and sftp error set.

See also

sftp_get_error()

source
LibSSH.lib.sftp_statvfsMethod
sftp_statvfs(sftp, path)

Get information about a mounted file system.

Arguments

  • sftp: The sftp session handle.
  • path: The pathname of any file within the mounted file system.

Returns

A statvfs structure or NULL on error.

See also

sftp_get_error()

source
LibSSH.lib.sftp_symlinkMethod
sftp_symlink(sftp, target, dest)

Create a symbolic link.

Arguments

  • sftp: The sftp session handle.
  • target: Specifies the target of the symlink.
  • dest: Specifies the path name of the symlink to be created.

Returns

0 on success, < 0 on error with ssh and sftp error set.

See also

sftp_get_error()

source
LibSSH.lib.sftp_tellMethod
sftp_tell(file)

Report current byte position in file.

Arguments

  • file: Open sftp file handle.

Returns

The offset of the current byte relative to the beginning of the file associated with the file descriptor. < 0 on error.

source
LibSSH.lib.sftp_tell64Method
sftp_tell64(file)

Report current byte position in file.

Arguments

  • file: Open sftp file handle.

Returns

The offset of the current byte relative to the beginning of the file associated with the file descriptor.

source
LibSSH.lib.sftp_unlinkMethod
sftp_unlink(sftp::sftp_session, file::Ptr{Cchar})

Auto-generated wrapper around sftp_unlink(). Original upstream documentation is below.


Unlink (delete) a file.

Arguments

  • sftp: The sftp session handle.
  • file: The file to unlink/delete.

Returns

0 on success, < 0 on error with ssh and sftp error set.

See also

sftp_get_error()

source
LibSSH.lib.sftp_utimesMethod
sftp_utimes(sftp, file, times)

Change the last modification and access time of a file.

Arguments

  • sftp: The sftp session handle.
  • file: The file which owner and group should be changed.
  • times: A timeval structure which contains the desired access and modification time.

Returns

0 on success, < 0 on error with ssh and sftp error set.

See also

sftp_get_error()

source
LibSSH.lib.sftp_writeMethod
sftp_write(file, buf, count)

Write to a file using an opened sftp file handle.

This function caps the length a user is allowed to write to an sftp file.

The value used for the cap is same as the value of the max_write_length field of the sftp_limits_t returned by sftp_limits().

Arguments

  • file: Open sftp file handle to write to.
  • buf: Pointer to buffer to write data.
  • count: Size of buffer in bytes.

Returns

Number of bytes written, < 0 on error with ssh and sftp error set.

See also

sftp_open(), sftp_read(), sftp_close()

source

Threading

LibSSH.lib.ssh_threads_set_callbacksMethod
ssh_threads_set_callbacks(cb)

Set the thread callbacks structure.

This is necessary if your program is using libssh in a multithreaded fashion. This function must be called first, outside of any threading context (in your main() function for instance), before you call ssh_init().

Known bug

libgcrypt 1.6 and bigger backend does not support custom callback. Using anything else than pthreads here will fail.

Arguments

Returns

Always returns SSH_OK.

See also

ssh_threads_callbacks_struct, SSH_THREADS_PTHREAD

source

Other

LibSSH.lib.ssh_auth_callbackType

SSH authentication callback for password and publickey auth.

Arguments

  • prompt: Prompt to be displayed.
  • buf: Buffer to save the password. You should null-terminate it.
  • len: Length of the buffer.
  • echo: Enable or disable the echo of what you type.
  • verify: Should the password be verified?
  • userdata: Userdata to be passed to the callback function. Useful for GUI applications.

Returns

0 on success, < 0 on error.

source
LibSSH.lib.ssh_auth_gssapi_mic_callbackType

SSH authentication callback. Tries to authenticates user with the "gssapi-with-mic" method

Warning

Implementations should verify that parameter user matches in some way the principal. user and principal can be different. Only the latter is guaranteed to be safe.

Arguments

  • session: Current session handler
  • user: Username of the user (can be spoofed)
  • principal: Authenticated principal of the user, including realm.
  • userdata: Userdata to be passed to the callback function.

Returns

SSH_AUTH_DENIED Authentication failed.

source
LibSSH.lib.ssh_auth_none_callbackType

SSH authentication callback. Tries to authenticates user with the "none" method which is anonymous or passwordless.

Arguments

  • session: Current session handler
  • user: User that wants to authenticate
  • userdata: Userdata to be passed to the callback function.

Returns

SSH_AUTH_DENIED Authentication failed.

source
LibSSH.lib.ssh_auth_password_callbackType

SSH authentication callback.

Arguments

  • session: Current session handler
  • user: User that wants to authenticate
  • password: Password used for authentication
  • userdata: Userdata to be passed to the callback function.

Returns

SSH_AUTH_DENIED Authentication failed.

source
LibSSH.lib.ssh_auth_pubkey_callbackType

SSH authentication callback.

Arguments

  • session: Current session handler
  • user: User that wants to authenticate
  • pubkey: public key used for authentication
  • signature_state: SSH_PUBLICKEY_STATE_NONE if the key is not signed (simple public key probe), SSH_PUBLICKEY_STATE_VALID if the signature is valid. Others values should be replied with a SSH_AUTH_DENIED.
  • userdata: Userdata to be passed to the callback function.

Returns

SSH_AUTH_DENIED Authentication failed.

source
LibSSH.lib.ssh_callback_dataType
 @brief callback for data received messages.
 @param data data retrieved from the socket or stream
 @param len number of bytes available from this stream
 @param user user-supplied pointer sent along with all callback messages
 @returns number of bytes processed by the callee. The remaining bytes will
 be sent in the next callback message, when more data is available.
 
source
LibSSH.lib.ssh_channel_auth_agent_req_callbackType

SSH auth-agent-request from the client. This request is sent by a client when agent forwarding is available. Server is free to ignore this callback, no answer is expected.

Arguments

  • session: the session
  • channel: the channel
  • userdata: Userdata to be passed to the callback function.
source
LibSSH.lib.ssh_channel_close_callbackType

SSH channel close callback. Called when a channel is closed by remote peer

Arguments

  • session: Current session handler
  • channel: the actual channel
  • userdata: Userdata to be passed to the callback function.
source
LibSSH.lib.ssh_channel_data_callbackType

SSH channel data callback. Called when data is available on a channel

Arguments

  • session: Current session handler
  • channel: the actual channel
  • data: the data that has been read on the channel
  • len: the length of the data
  • is_stderr: is 0 for stdout or 1 for stderr
  • userdata: Userdata to be passed to the callback function.

Returns

number of bytes processed by the callee. The remaining bytes will be sent in the next callback message, when more data is available.

source
LibSSH.lib.ssh_channel_env_request_callbackType

SSH channel environment request from a client.

Warning

some environment variables can be dangerous if changed (e.g. LD_PRELOAD) and should not be fulfilled.

Arguments

  • session: the session
  • channel: the channel
  • env_name: name of the environment value to be set
  • env_value: value of the environment value to be set
  • userdata: Userdata to be passed to the callback function.

Returns

1 if the request is denied

source
LibSSH.lib.ssh_channel_eof_callbackType

SSH channel eof callback. Called when a channel receives EOF

Arguments

  • session: Current session handler
  • channel: the actual channel
  • userdata: Userdata to be passed to the callback function.
source
LibSSH.lib.ssh_channel_exec_request_callbackType

SSH channel Exec request from a client.

Arguments

  • session: the session
  • channel: the channel
  • command: the shell command to be executed
  • userdata: Userdata to be passed to the callback function.

Returns

1 if the request is denied

source
LibSSH.lib.ssh_channel_exit_signal_callbackType

SSH channel exit signal callback. Called when a channel has received an exit signal

Arguments

  • session: Current session handler
  • channel: the actual channel
  • signal: the signal name (without the SIG prefix)
  • core: a boolean telling whether a core has been dumped or not
  • errmsg: the description of the exception
  • lang: the language of the description (format: RFC 3066)
  • userdata: Userdata to be passed to the callback function.
source
LibSSH.lib.ssh_channel_exit_status_callbackType

SSH channel exit status callback. Called when a channel has received an exit status

Arguments

  • session: Current session handler
  • channel: the actual channel
  • exit_status: Exit status of the ran command
  • userdata: Userdata to be passed to the callback function.
source
LibSSH.lib.ssh_channel_open_request_auth_agent_callbackType

Handles an SSH new channel open "auth-agent" request. This happens when the server sends back an "auth-agent" connection attempt. This is a client-side API

Warning

The channel pointer returned by this callback must be closed by the application.

Arguments

  • session: current session handler
  • userdata: Userdata to be passed to the callback function.

Returns

NULL if the request should not be allowed

source
LibSSH.lib.ssh_channel_open_request_forwarded_tcpip_callbackType

Handles an SSH new channel open "forwarded-tcpip" request. This happens when the server forwards an incoming TCP connection on a port it was previously requested to listen on. This is a client-side API

Warning

The channel pointer returned by this callback must be closed by the application.

Arguments

  • session: current session handler
  • destination_address: the address that the TCP connection connected to
  • destination_port: the port that the TCP connection connected to
  • originator_address: the originator IP address
  • originator_port: the originator port
  • userdata: Userdata to be passed to the callback function.

Returns

NULL if the request should not be allowed

source
LibSSH.lib.ssh_channel_open_request_session_callbackType

Handles an SSH new channel open session request

Warning

The channel pointer returned by this callback must be closed by the application.

Arguments

  • session: current session handler
  • userdata: Userdata to be passed to the callback function.

Returns

NULL if the request should not be allowed

source
LibSSH.lib.ssh_channel_open_request_x11_callbackType

Handles an SSH new channel open X11 request. This happens when the server sends back an X11 connection attempt. This is a client-side API

Warning

The channel pointer returned by this callback must be closed by the application.

Arguments

  • session: current session handler
  • userdata: Userdata to be passed to the callback function.
  • originator_address: IP address of the machine who sent the request
  • originator_port: port number of the machine who sent the request

Returns

NULL if the request should not be allowed

source
LibSSH.lib.ssh_channel_open_resp_callbackType

SSH channel open callback. Called when a channel open succeeds or fails.

Arguments

  • session: Current session handler
  • channel: the actual channel
  • is_success: is 1 when the open succeeds, and 0 otherwise.
  • userdata: Userdata to be passed to the callback function.
source
LibSSH.lib.ssh_channel_pty_request_callbackType

SSH channel PTY request from a client.

Arguments

  • session: the session
  • channel: the channel
  • term: The type of terminal emulation
  • width: width of the terminal, in characters
  • height: height of the terminal, in characters
  • pxwidth: width of the terminal, in pixels
  • pwheight: height of the terminal, in pixels
  • userdata: Userdata to be passed to the callback function.

Returns

-1 if the request is denied

source
LibSSH.lib.ssh_channel_pty_window_change_callbackType

SSH channel PTY windows change (terminal size) from a client.

Arguments

  • session: the session
  • channel: the channel
  • width: width of the terminal, in characters
  • height: height of the terminal, in characters
  • pxwidth: width of the terminal, in pixels
  • pwheight: height of the terminal, in pixels
  • userdata: Userdata to be passed to the callback function.

Returns

-1 if the request is denied

source
LibSSH.lib.ssh_channel_request_resp_callbackType

SSH channel request response callback. Called when a response to the pending request is received.

Arguments

  • session: Current session handler
  • channel: the actual channel
  • userdata: Userdata to be passed to the callback function.
source
LibSSH.lib.ssh_channel_signal_callbackType

SSH channel signal callback. Called when a channel has received a signal

Arguments

  • session: Current session handler
  • channel: the actual channel
  • signal: the signal name (without the SIG prefix)
  • userdata: Userdata to be passed to the callback function.
source
LibSSH.lib.ssh_channel_subsystem_request_callbackType

SSH channel subsystem request from a client.

Arguments

  • session: the session
  • channel: the channel
  • subsystem: the subsystem required
  • userdata: Userdata to be passed to the callback function.

Returns

1 if the request is denied

source
LibSSH.lib.ssh_channel_write_wontblock_callbackType

SSH channel write will not block (flow control).

Arguments

  • session: the session
  • channel: the channel
  • bytes:[in] size of the remote window in bytes. Writing as much data will not block.
  • userdata:[in] Userdata to be passed to the callback function.

Returns

0 default return value (other return codes may be added in future).

source
LibSSH.lib.ssh_channel_x11_req_callbackType

SSH X11 request from the client. This request is sent by a client when X11 forwarding is requested(and available). Server is free to ignore this callback, no answer is expected.

Arguments

  • session: the session
  • channel: the channel
  • single_connection: If true, only one channel should be forwarded
  • auth_protocol: The X11 authentication method to be used
  • auth_cookie: Authentication cookie encoded hexadecimal
  • screen_number: Screen number
  • userdata: Userdata to be passed to the callback function.
source
LibSSH.lib.ssh_global_request_callbackType

SSH global request callback. All global request will go through this callback.

Arguments

  • session: Current session handler
  • message: the actual message
  • userdata: Userdata to be passed to the callback function.
source
LibSSH.lib.ssh_jump_authenticate_callbackType

SSH proxyjump user authentication callback. Authenticate the user.

Arguments

  • session: Jump session handler
  • userdata: Userdata to be passed to the callback function.

Returns

0 on success, < 0 on error.

source
LibSSH.lib.ssh_jump_verify_knownhost_callbackType

SSH proxyjump verify knownhost callback. Verify the host. If not specified default function will be used.

Arguments

  • session: Jump session handler
  • userdata: Userdata to be passed to the callback function.

Returns

0 on success, < 0 on error.

source
LibSSH.lib.ssh_log_callbackType

SSH log callback. All logging messages will go through this callback

Arguments

  • session: Current session handler
  • priority: Priority of the log, the smaller being the more important
  • message: the actual message
  • userdata: Userdata to be passed to the callback function.
source
LibSSH.lib.ssh_logging_callbackType

SSH log callback.

All logging messages will go through this callback.

Arguments

  • priority: Priority of the log, the smaller being the more important.
  • function: The function name calling the logging functions.
  • buffer: The actual message
  • userdata: Userdata to be passed to the callback function.
source
LibSSH.lib.ssh_packet_callbackType

Prototype for a packet callback, to be called when a new packet arrives

Arguments

  • session: The current session of the packet
  • type: packet type (see ssh2.h)
  • packet: buffer containing the packet, excluding size, type and padding fields
  • user: user argument to the callback and are called each time a packet shows up

Returns

SSH_PACKET_NOT_USED Packet was not used or understood, processing must continue

source
LibSSH.lib.ssh_service_request_callbackType

Handles an SSH service request

Arguments

  • session: current session handler
  • service: name of the service (e.g. "ssh-userauth") requested
  • userdata: Userdata to be passed to the callback function.

Returns

-1 if the request should not be allowed

source
LibSSH.lib.ssh_status_callbackType

SSH Connection status callback.

Arguments

  • session: Current session handler
  • status: Percentage of connection status, going from 0.0 to 1.0 once connection is done.
  • userdata: Userdata to be passed to the callback function.
source