sftp_client.c File Reference

SFTP client. More...

#include "ssh/ssh.h"
#include "ssh/ssh_transport.h"
#include "sftp/sftp_client.h"
#include "sftp/sftp_client_packet.h"
#include "sftp/sftp_client_misc.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   SFTP_TRACE_LEVEL
 

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_tsftpClientGetWorkingDir (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.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.4

Definition in file sftp_client.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   SFTP_TRACE_LEVEL

Definition at line 32 of file sftp_client.c.

Function Documentation

◆ sftpClientBindToInterface()

error_t sftpClientBindToInterface ( SftpClientContext context,
NetInterface interface 
)

Bind the SFTP client to a particular network interface.

Parameters
[in]contextPointer to the SFTP client context
[in]interfaceNetwork 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]contextPointer 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]contextPointer to the SFTP client context
[in]pathNew 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]contextPointer 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]contextPointer 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]contextPointer 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]contextPointer to the SFTP client context
[in]serverIpAddrIP address of the SFTP server to connect to
[in]serverPortPort 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]contextPointer to the SFTP client context
[in]pathName 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]contextPointer 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]contextPointer to the SFTP client context
[in]pathPath 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]contextPointer to the SFTP client context
[in]pathPath 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]contextPointer 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]contextPointer 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]contextPointer 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]contextPointer 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]contextPointer to the SFTP client context
[in]pathPath 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]contextPointer to the SFTP client context
[in]pathPath to the file to be be opened
[in]modeFile 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]contextPointer to the SFTP client context
[out]dirEntryPointer 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]contextPointer to the SFTP client context
[out]dataBuffer where to store the incoming data
[in]sizeMaximum number of bytes that can be read
[out]receivedActual number of bytes that have been read
[in]flagsSet 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]contextPointer to the SFTP client context
[in]callbackSSH 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]contextPointer to the SFTP client context
[in]oldPathName of an existing file or directory
[in]newPathNew 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]contextPointer to the SFTP client context
[in]timeoutTimeout 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]contextPointer to the SFTP client context
[in]dataPointer to a buffer containing the data to be written
[in]lengthNumber of data bytes to write
[in]writtenNumber of bytes that have been written (optional parameter)
[in]flagsSet of flags that influences the behavior of this function
Returns
Error code

Definition at line 912 of file sftp_client.c.