sftp_server_file.c File Reference

File operations. More...

#include "ssh/ssh.h"
#include "sftp/sftp_server.h"
#include "sftp/sftp_server_file.h"
#include "sftp/sftp_server_misc.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   SFTP_TRACE_LEVEL
 

Functions

error_t sftpServerGetRealPath (SftpServerSession *session, const SshString *path, SftpName *name)
 Canonicalize a given path name to an absolute path. More...
 
error_t sftpServerGetFileStat (SftpServerSession *session, const SshString *path, SftpFileAttrs *attributes)
 Retrieve file attributes. More...
 
error_t sftpServerGetFileStatEx (SftpServerSession *session, const SshBinaryString *handle, SftpFileAttrs *attributes)
 Retrieve file attributes. More...
 
error_t sftpServerSetFileStat (SftpServerSession *session, const SshString *path, const SftpFileAttrs *attributes)
 Modify file attributes. More...
 
error_t sftpServerSetFileStatEx (SftpServerSession *session, const SshBinaryString *handle, const SftpFileAttrs *attributes)
 Modify file attributes. More...
 
error_t sftpServerRenameFile (SftpServerSession *session, const SshString *oldPath, const SshString *newPath)
 Rename the specified file. More...
 
error_t sftpServerRemoveFile (SftpServerSession *session, const SshString *path)
 Remove a file. More...
 
error_t sftpServerOpenFile (SftpServerSession *session, const SshString *path, uint32_t pflags, const SftpFileAttrs *attributes, uint32_t *handle)
 Open a file. More...
 
error_t sftpServerWriteFile (SftpServerSession *session, const SshBinaryString *handle, uint64_t offset, const uint8_t *data, uint32_t fragLen, uint32_t totalLen)
 Write the specified file. More...
 
error_t sftpServerWriteData (SftpServerSession *session)
 Write data to the specified file. More...
 
error_t sftpServerReadFile (SftpServerSession *session, const SshBinaryString *handle, uint64_t offset, uint32_t *length)
 Read the specified file. More...
 
error_t sftpServerReadData (SftpServerSession *session)
 Read data from the specified file. More...
 
error_t sftpServerCloseFile (SftpServerSession *session, const SshBinaryString *handle)
 Close a file. More...
 
SftpFileObjectsftpServerFindFile (SftpServerSession *session, const SshBinaryString *handle)
 Find the file that matches a given handle. More...
 

Detailed Description

File operations.

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_server_file.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   SFTP_TRACE_LEVEL

Definition at line 32 of file sftp_server_file.c.

Function Documentation

◆ sftpServerCloseFile()

error_t sftpServerCloseFile ( SftpServerSession session,
const SshBinaryString handle 
)

Close a file.

Parameters
[in]sessionHandle referencing an SFTP session
[in]handleFile handle returned by SSH_FXP_OPEN
Returns
Error code

Definition at line 780 of file sftp_server_file.c.

◆ sftpServerFindFile()

SftpFileObject* sftpServerFindFile ( SftpServerSession session,
const SshBinaryString handle 
)

Find the file that matches a given handle.

Parameters
[in]sessionHandle referencing an SFTP session
[in]handleOpaque variable-length string
Returns
Pointer to the matching file object

Definition at line 821 of file sftp_server_file.c.

◆ sftpServerGetFileStat()

error_t sftpServerGetFileStat ( SftpServerSession session,
const SshString path,
SftpFileAttrs attributes 
)

Retrieve file attributes.

Parameters
[in]sessionHandle referencing an SFTP session
[in]pathPath name of the file for which status is to be returned
[out]attributesFile attributes
Returns
Error code

Definition at line 93 of file sftp_server_file.c.

◆ sftpServerGetFileStatEx()

error_t sftpServerGetFileStatEx ( SftpServerSession session,
const SshBinaryString handle,
SftpFileAttrs attributes 
)

Retrieve file attributes.

Parameters
[in]sessionHandle referencing an SFTP session
[in]handleOpaque value that identifies the file
[out]attributesFile attributes
Returns
Error code

Definition at line 191 of file sftp_server_file.c.

◆ sftpServerGetRealPath()

error_t sftpServerGetRealPath ( SftpServerSession session,
const SshString path,
SftpName name 
)

Canonicalize a given path name to an absolute path.

Parameters
[in]sessionHandle referencing an SFTP session
[in]pathPath name to be canonicalized
[out]nameName in canonical form
Returns
Error code

Definition at line 53 of file sftp_server_file.c.

◆ sftpServerOpenFile()

error_t sftpServerOpenFile ( SftpServerSession session,
const SshString path,
uint32_t  pflags,
const SftpFileAttrs attributes,
uint32_t *  handle 
)

Open a file.

Parameters
[in]sessionHandle referencing an SFTP session
[in]pathPath name of the file
[in]pflagsBitmask that specifies the desired access mode
[in]attributesInitial attributes for the file
[out]handleOpaque value that identifies the file
Returns
Error code

Definition at line 397 of file sftp_server_file.c.

◆ sftpServerReadData()

error_t sftpServerReadData ( SftpServerSession session)

Read data from the specified file.

Parameters
[in]sessionHandle referencing an SFTP session
Returns
error

Definition at line 731 of file sftp_server_file.c.

◆ sftpServerReadFile()

error_t sftpServerReadFile ( SftpServerSession session,
const SshBinaryString handle,
uint64_t  offset,
uint32_t *  length 
)

Read the specified file.

Parameters
[in]sessionHandle referencing an SFTP session
[in]handleOpaque value that identifies the file
[in]offsetOffset relative to the beginning of the file from where to start reading
[in,out]lengthMaximum number of bytes to read (input value) and actual length of the data (output value)
Returns
Error code

Definition at line 660 of file sftp_server_file.c.

◆ sftpServerRemoveFile()

error_t sftpServerRemoveFile ( SftpServerSession session,
const SshString path 
)

Remove a file.

Parameters
[in]sessionHandle referencing an SFTP session
[in]pathPathname of the file to be removed
Returns
Error code

Definition at line 356 of file sftp_server_file.c.

◆ sftpServerRenameFile()

error_t sftpServerRenameFile ( SftpServerSession session,
const SshString oldPath,
const SshString newPath 
)

Rename the specified file.

Parameters
[in]sessionHandle referencing an SFTP session
[in]oldPathPathname of the file to be renamed
[in]newPathNew filename
Returns
Error code

Definition at line 302 of file sftp_server_file.c.

◆ sftpServerSetFileStat()

error_t sftpServerSetFileStat ( SftpServerSession session,
const SshString path,
const SftpFileAttrs attributes 
)

Modify file attributes.

Parameters
[in]sessionHandle referencing an SFTP session
[in]pathPath name of the file
[in]attributesFile attributes
Returns
Error code

Definition at line 231 of file sftp_server_file.c.

◆ sftpServerSetFileStatEx()

error_t sftpServerSetFileStatEx ( SftpServerSession session,
const SshBinaryString handle,
const SftpFileAttrs attributes 
)

Modify file attributes.

Parameters
[in]sessionHandle referencing an SFTP session
[in]handleOpaque value that identifies the file
[in]attributesFile attributes
Returns
Error code

Definition at line 267 of file sftp_server_file.c.

◆ sftpServerWriteData()

error_t sftpServerWriteData ( SftpServerSession session)

Write data to the specified file.

Parameters
[in]sessionHandle referencing an SFTP session
Returns
Error code

Definition at line 623 of file sftp_server_file.c.

◆ sftpServerWriteFile()

error_t sftpServerWriteFile ( SftpServerSession session,
const SshBinaryString handle,
uint64_t  offset,
const uint8_t *  data,
uint32_t  fragLen,
uint32_t  totalLen 
)

Write the specified file.

Parameters
[in]sessionHandle referencing an SFTP session
[in]handleOpaque value that identifies the file
[in]offsetOffset from the beginning of the file where to start writing
[in]dataData to be written
[in]fragLenNumber of bytes available on hand
[in]totalLenTotal length of the data, in bytes
Returns
Error code

Definition at line 561 of file sftp_server_file.c.