SFTP client. More...
Go to the source code of this file.
Data Structures | |
struct | _SftpClientContext |
SFTP client context. More... | |
struct | SftpDirEntry |
Directory entry. More... | |
Macros | |
#define | SFTP_CLIENT_SUPPORT DISABLED |
#define | SFTP_CLIENT_MIN_VERSION 1 |
#define | SFTP_CLIENT_MAX_VERSION 3 |
#define | SFTP_CLIENT_DEFAULT_TIMEOUT 20000 |
#define | SFTP_CLIENT_MAX_PACKET_SIZE 32768 |
#define | SFTP_CLIENT_BUFFER_SIZE 1024 |
#define | SFTP_CLIENT_MAX_HANDLE_SIZE 32 |
#define | SFTP_CLIENT_MAX_FILENAME_LEN 64 |
#define | SFTP_CLIENT_MAX_PATH_LEN 128 |
#define | SftpClientContext struct _SftpClientContext |
Typedefs | |
typedef error_t(* | SftpClientSshInitCallback) (SftpClientContext *context, SshContext *sshContext) |
SSH initialization callback function. More... | |
Enumerations | |
enum | SftpClientState { SFTP_CLIENT_STATE_DISCONNECTED = 0, SFTP_CLIENT_STATE_CONNECTING = 1, SFTP_CLIENT_STATE_CONNECTED = 2, SFTP_CLIENT_STATE_CHANNEL_OPEN = 3, SFTP_CLIENT_STATE_CHANNEL_OPEN_REPLY = 4, SFTP_CLIENT_STATE_CHANNEL_REQUEST = 5, SFTP_CLIENT_STATE_CHANNEL_REPLY = 6, SFTP_CLIENT_STATE_CHANNEL_DATA = 7, SFTP_CLIENT_STATE_SENDING_COMMAND_1 = 8, SFTP_CLIENT_STATE_SENDING_COMMAND_2 = 9, SFTP_CLIENT_STATE_SENDING_DATA = 10, SFTP_CLIENT_STATE_RECEIVING_DATA = 11, SFTP_CLIENT_STATE_RECEIVING_NAME = 12, SFTP_CLIENT_STATE_DISCONNECTING_1 = 13, SFTP_CLIENT_STATE_DISCONNECTING_2 = 14, SFTP_CLIENT_STATE_DISCONNECTING_3 = 15 } |
SFTP client state. More... | |
Functions | |
error_t | sftpClientInit (SftpClientContext *context) |
Initialize SFTP client context. More... | |
error_t | sftpClientRegisterSshInitCallback (SftpClientContext *context, SftpClientSshInitCallback callback) |
Register SSH initialization callback function. More... | |
error_t | sftpClientSetTimeout (SftpClientContext *context, systime_t timeout) |
Set communication timeout. More... | |
error_t | sftpClientBindToInterface (SftpClientContext *context, NetInterface *interface) |
Bind the SFTP client to a particular network interface. More... | |
error_t | sftpClientConnect (SftpClientContext *context, const IpAddr *serverIpAddr, uint16_t serverPort) |
Establish a connection with the specified SFTP server. More... | |
const char_t * | sftpClientGetWorkingDir (SftpClientContext *context) |
Get current working directory. More... | |
error_t | sftpClientChangeWorkingDir (SftpClientContext *context, const char_t *path) |
Change working directory. More... | |
error_t | sftpClientChangeToParentDir (SftpClientContext *context) |
Change to parent directory. More... | |
error_t | sftpClientOpenDir (SftpClientContext *context, const char_t *path) |
Open a directory. More... | |
error_t | sftpClientReadDir (SftpClientContext *context, SftpDirEntry *dirEntry) |
Read an entry from the directory. More... | |
error_t | sftpClientCloseDir (SftpClientContext *context) |
Close directory. More... | |
error_t | sftpClientCreateDir (SftpClientContext *context, const char_t *path) |
Create a new directory. More... | |
error_t | sftpClientDeleteDir (SftpClientContext *context, const char_t *path) |
Remove a directory. More... | |
error_t | sftpClientOpenFile (SftpClientContext *context, const char_t *path, uint_t mode) |
Open a file for reading, writing, or appending. More... | |
error_t | sftpClientWriteFile (SftpClientContext *context, const void *data, size_t length, size_t *written, uint_t flags) |
Write to a remote file. More... | |
error_t | sftpClientReadFile (SftpClientContext *context, void *data, size_t size, size_t *received, uint_t flags) |
Read from a remote file. More... | |
error_t | sftpClientCloseFile (SftpClientContext *context) |
Close file. More... | |
error_t | sftpClientRenameFile (SftpClientContext *context, const char_t *oldPath, const char_t *newPath) |
Rename a file. More... | |
error_t | sftpClientDeleteFile (SftpClientContext *context, const char_t *path) |
Delete a file. More... | |
SftpStatusCode | sftpClientGetStatusCode (SftpClientContext *context) |
Retrieve SFTP status code. More... | |
error_t | sftpClientDisconnect (SftpClientContext *context) |
Gracefully disconnect from the SFTP server. More... | |
error_t | sftpClientClose (SftpClientContext *context) |
Close the connection with the SFTP server. More... | |
void | sftpClientDeinit (SftpClientContext *context) |
Release SFTP client context. More... | |
Detailed Description
SFTP client.
License
SPDX-License-Identifier: GPL-2.0-or-later
Copyright (C) 2019-2024 Oryx Embedded SARL. All rights reserved.
This file is part of CycloneSSH Open.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- Version
- 2.4.4
Definition in file sftp_client.h.
Macro Definition Documentation
◆ SFTP_CLIENT_BUFFER_SIZE
#define SFTP_CLIENT_BUFFER_SIZE 1024 |
Definition at line 75 of file sftp_client.h.
◆ SFTP_CLIENT_DEFAULT_TIMEOUT
#define SFTP_CLIENT_DEFAULT_TIMEOUT 20000 |
Definition at line 61 of file sftp_client.h.
◆ SFTP_CLIENT_MAX_FILENAME_LEN
#define SFTP_CLIENT_MAX_FILENAME_LEN 64 |
Definition at line 89 of file sftp_client.h.
◆ SFTP_CLIENT_MAX_HANDLE_SIZE
#define SFTP_CLIENT_MAX_HANDLE_SIZE 32 |
Definition at line 82 of file sftp_client.h.
◆ SFTP_CLIENT_MAX_PACKET_SIZE
#define SFTP_CLIENT_MAX_PACKET_SIZE 32768 |
Definition at line 68 of file sftp_client.h.
◆ SFTP_CLIENT_MAX_PATH_LEN
#define SFTP_CLIENT_MAX_PATH_LEN 128 |
Definition at line 96 of file sftp_client.h.
◆ SFTP_CLIENT_MAX_VERSION
#define SFTP_CLIENT_MAX_VERSION 3 |
Definition at line 54 of file sftp_client.h.
◆ SFTP_CLIENT_MIN_VERSION
#define SFTP_CLIENT_MIN_VERSION 1 |
Definition at line 47 of file sftp_client.h.
◆ SFTP_CLIENT_SUPPORT
#define SFTP_CLIENT_SUPPORT DISABLED |
Definition at line 40 of file sftp_client.h.
◆ SftpClientContext
#define SftpClientContext struct _SftpClientContext |
Definition at line 103 of file sftp_client.h.
Typedef Documentation
◆ SftpClientSshInitCallback
typedef error_t(* SftpClientSshInitCallback) (SftpClientContext *context, SshContext *sshContext) |
SSH initialization callback function.
Definition at line 140 of file sftp_client.h.
Enumeration Type Documentation
◆ SftpClientState
enum SftpClientState |
SFTP client state.
Definition at line 115 of file sftp_client.h.
Function Documentation
◆ sftpClientBindToInterface()
error_t sftpClientBindToInterface | ( | SftpClientContext * | context, |
NetInterface * | interface | ||
) |
Bind the SFTP client to a particular network interface.
- Parameters
-
[in] context Pointer to the SFTP client context [in] interface Network interface to be used
- Returns
- Error code
Definition at line 121 of file sftp_client.c.
◆ sftpClientChangeToParentDir()
error_t sftpClientChangeToParentDir | ( | SftpClientContext * | context | ) |
Change to parent directory.
- Parameters
-
[in] context Pointer to the SFTP client context
- Returns
- Error code
Definition at line 434 of file sftp_client.c.
◆ sftpClientChangeWorkingDir()
error_t sftpClientChangeWorkingDir | ( | SftpClientContext * | context, |
const char_t * | path | ||
) |
Change working directory.
- Parameters
-
[in] context Pointer to the SFTP client context [in] path New current working directory
- Returns
- Error code
Definition at line 340 of file sftp_client.c.
◆ sftpClientClose()
error_t sftpClientClose | ( | SftpClientContext * | context | ) |
Close the connection with the SFTP server.
- Parameters
-
[in] context Pointer to the SFTP client context
- Returns
- Error code
Definition at line 1571 of file sftp_client.c.
◆ sftpClientCloseDir()
error_t sftpClientCloseDir | ( | SftpClientContext * | context | ) |
Close directory.
- Parameters
-
[in] context Pointer to the SFTP client context
- Returns
- Error code
Definition at line 663 of file sftp_client.c.
◆ sftpClientCloseFile()
error_t sftpClientCloseFile | ( | SftpClientContext * | context | ) |
Close file.
- Parameters
-
[in] context Pointer to the SFTP client context
- Returns
- Error code
Definition at line 1237 of file sftp_client.c.
◆ sftpClientConnect()
error_t sftpClientConnect | ( | SftpClientContext * | context, |
const IpAddr * | serverIpAddr, | ||
uint16_t | serverPort | ||
) |
Establish a connection with the specified SFTP server.
- Parameters
-
[in] context Pointer to the SFTP client context [in] serverIpAddr IP address of the SFTP server to connect to [in] serverPort Port number
- Returns
- Error code
Definition at line 144 of file sftp_client.c.
◆ sftpClientCreateDir()
error_t sftpClientCreateDir | ( | SftpClientContext * | context, |
const char_t * | path | ||
) |
Create a new directory.
- Parameters
-
[in] context Pointer to the SFTP client context [in] path Name of the new directory
- Returns
- Error code
Definition at line 724 of file sftp_client.c.
◆ sftpClientDeinit()
void sftpClientDeinit | ( | SftpClientContext * | context | ) |
Release SFTP client context.
- Parameters
-
[in] context Pointer to the SFTP client context
Definition at line 1592 of file sftp_client.c.
◆ sftpClientDeleteDir()
error_t sftpClientDeleteDir | ( | SftpClientContext * | context, |
const char_t * | path | ||
) |
Remove a directory.
- Parameters
-
[in] context Pointer to the SFTP client context [in] path Path to the directory to be removed
- Returns
- Error code
Definition at line 784 of file sftp_client.c.
◆ sftpClientDeleteFile()
error_t sftpClientDeleteFile | ( | SftpClientContext * | context, |
const char_t * | path | ||
) |
Delete a file.
- Parameters
-
[in] context Pointer to the SFTP client context [in] path Path to the file to be be deleted
- Returns
- Error code
Definition at line 1364 of file sftp_client.c.
◆ sftpClientDisconnect()
error_t sftpClientDisconnect | ( | SftpClientContext * | context | ) |
Gracefully disconnect from the SFTP server.
- Parameters
-
[in] context Pointer to the SFTP client context
- Returns
- Error code
Definition at line 1450 of file sftp_client.c.
◆ sftpClientGetStatusCode()
SftpStatusCode sftpClientGetStatusCode | ( | SftpClientContext * | context | ) |
Retrieve SFTP status code.
- Parameters
-
[in] context Pointer to the SFTP client context
- Returns
- SFTP status code
Definition at line 1423 of file sftp_client.c.
◆ sftpClientGetWorkingDir()
const char_t* sftpClientGetWorkingDir | ( | SftpClientContext * | context | ) |
Get current working directory.
- Parameters
-
[in] context Pointer to the SFTP client context
- Returns
- Path of the current directory
Definition at line 313 of file sftp_client.c.
◆ sftpClientInit()
error_t sftpClientInit | ( | SftpClientContext * | context | ) |
Initialize SFTP client context.
- Parameters
-
[in] context Pointer to the SFTP client context
- Returns
- Error code
Definition at line 52 of file sftp_client.c.
◆ sftpClientOpenDir()
error_t sftpClientOpenDir | ( | SftpClientContext * | context, |
const char_t * | path | ||
) |
Open a directory.
- Parameters
-
[in] context Pointer to the SFTP client context [in] path Path to the directory to be be opened
- Returns
- Directory handle
Definition at line 448 of file sftp_client.c.
◆ sftpClientOpenFile()
error_t sftpClientOpenFile | ( | SftpClientContext * | context, |
const char_t * | path, | ||
uint_t | mode | ||
) |
Open a file for reading, writing, or appending.
- Parameters
-
[in] context Pointer to the SFTP client context [in] path Path to the file to be be opened [in] mode File access mode
- Returns
- Error code
Definition at line 845 of file sftp_client.c.
◆ sftpClientReadDir()
error_t sftpClientReadDir | ( | SftpClientContext * | context, |
SftpDirEntry * | dirEntry | ||
) |
Read an entry from the directory.
- Parameters
-
[in] context Pointer to the SFTP client context [out] dirEntry Pointer to a directory entry
- Returns
- Error code
Definition at line 508 of file sftp_client.c.
◆ sftpClientReadFile()
error_t sftpClientReadFile | ( | SftpClientContext * | context, |
void * | data, | ||
size_t | size, | ||
size_t * | received, | ||
uint_t | flags | ||
) |
Read from a remote file.
- Parameters
-
[in] context Pointer to the SFTP client context [out] data Buffer where to store the incoming data [in] size Maximum number of bytes that can be read [out] received Actual number of bytes that have been read [in] flags Set of flags that influences the behavior of this function
- Returns
- Error code
Definition at line 1086 of file sftp_client.c.
◆ sftpClientRegisterSshInitCallback()
error_t sftpClientRegisterSshInitCallback | ( | SftpClientContext * | context, |
SftpClientSshInitCallback | callback | ||
) |
Register SSH initialization callback function.
- Parameters
-
[in] context Pointer to the SFTP client context [in] callback SSH initialization callback function
- Returns
- Error code
Definition at line 78 of file sftp_client.c.
◆ sftpClientRenameFile()
error_t sftpClientRenameFile | ( | SftpClientContext * | context, |
const char_t * | oldPath, | ||
const char_t * | newPath | ||
) |
Rename a file.
- Parameters
-
[in] context Pointer to the SFTP client context [in] oldPath Name of an existing file or directory [in] newPath New name for the file or directory
- Returns
- Error code
Definition at line 1299 of file sftp_client.c.
◆ sftpClientSetTimeout()
error_t sftpClientSetTimeout | ( | SftpClientContext * | context, |
systime_t | timeout | ||
) |
Set communication timeout.
- Parameters
-
[in] context Pointer to the SFTP client context [in] timeout Timeout value, in milliseconds
- Returns
- Error code
Definition at line 100 of file sftp_client.c.
◆ sftpClientWriteFile()
error_t sftpClientWriteFile | ( | SftpClientContext * | context, |
const void * | data, | ||
size_t | length, | ||
size_t * | written, | ||
uint_t | flags | ||
) |
Write to a remote file.
- Parameters
-
[in] context Pointer to the SFTP client context [in] data Pointer to a buffer containing the data to be written [in] length Number of data bytes to write [in] written Number of bytes that have been written (optional parameter) [in] flags Set of flags that influences the behavior of this function
- Returns
- Error code
Definition at line 912 of file sftp_client.c.