scp_client.h File Reference

SCP client. More...

#include "ssh/ssh.h"
#include "scp/scp_common.h"

Go to the source code of this file.

Data Structures

struct  _ScpClientContext
 SCP client context. More...
 

Macros

#define SCP_CLIENT_SUPPORT   DISABLED
 
#define SCP_CLIENT_DEFAULT_TIMEOUT   20000
 
#define SCP_CLIENT_BUFFER_SIZE   512
 
#define ScpClientContext   struct _ScpClientContext
 

Typedefs

typedef error_t(* ScpClientSshInitCallback) (ScpClientContext *context, SshContext *sshContext)
 SSH initialization callback function. More...
 

Enumerations

enum  ScpClientState {
  SCP_CLIENT_STATE_DISCONNECTED = 0 , SCP_CLIENT_STATE_CONNECTING_1 = 1 , SCP_CLIENT_STATE_CONNECTING_2 = 2 , SCP_CLIENT_STATE_CONNECTED = 3 ,
  SCP_CLIENT_STATE_CHANNEL_OPEN = 4 , SCP_CLIENT_STATE_CHANNEL_REQUEST = 6 , SCP_CLIENT_STATE_CHANNEL_REPLY = 7 , SCP_CLIENT_STATE_WRITE_INIT = 8 ,
  SCP_CLIENT_STATE_WRITE_COMMAND = 9 , SCP_CLIENT_STATE_WRITE_ACK = 10 , SCP_CLIENT_STATE_WRITE_DATA = 11 , SCP_CLIENT_STATE_WRITE_STATUS = 12 ,
  SCP_CLIENT_STATE_WRITE_FIN = 13 , SCP_CLIENT_STATE_READ_INIT = 14 , SCP_CLIENT_STATE_READ_COMMAND = 15 , SCP_CLIENT_STATE_READ_ACK = 16 ,
  SCP_CLIENT_STATE_READ_DATA = 17 , SCP_CLIENT_STATE_READ_STATUS = 18 , SCP_CLIENT_STATE_READ_FIN = 19 , SCP_CLIENT_STATE_CHANNEL_CLOSE = 20 ,
  SCP_CLIENT_STATE_DISCONNECTING_1 = 21 , SCP_CLIENT_STATE_DISCONNECTING_2 = 22
}
 SCP client state. More...
 

Functions

error_t scpClientInit (ScpClientContext *context)
 Initialize SCP client context. More...
 
error_t scpClientRegisterSshInitCallback (ScpClientContext *context, ScpClientSshInitCallback callback)
 Register SSH initialization callback function. More...
 
error_t scpClientSetTimeout (ScpClientContext *context, systime_t timeout)
 Set communication timeout. More...
 
error_t scpClientBindToInterface (ScpClientContext *context, NetInterface *interface)
 Bind the SCP client to a particular network interface. More...
 
error_t scpClientConnect (ScpClientContext *context, const IpAddr *serverIpAddr, uint16_t serverPort)
 Establish a connection with the specified SCP server. More...
 
error_t scpClientOpenFileForWriting (ScpClientContext *context, const char_t *path, uint_t mode, uint64_t size)
 Open a file for writing. More...
 
error_t scpClientOpenFileForReading (ScpClientContext *context, const char_t *path, uint64_t *size)
 Open a file for reading. More...
 
error_t scpClientWriteFile (ScpClientContext *context, const void *data, size_t length, size_t *written, uint_t flags)
 Write to a remote file. More...
 
error_t scpClientReadFile (ScpClientContext *context, void *data, size_t size, size_t *received, uint_t flags)
 Read from a remote file. More...
 
error_t scpClientCloseFile (ScpClientContext *context)
 Close file. More...
 
error_t scpClientDisconnect (ScpClientContext *context)
 Gracefully disconnect from the SCP server. More...
 
error_t scpClientClose (ScpClientContext *context)
 Close the connection with the SCP server. More...
 
void scpClientDeinit (ScpClientContext *context)
 Release SCP client context. More...
 

Detailed Description

SCP 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.0

Definition in file scp_client.h.

Macro Definition Documentation

◆ SCP_CLIENT_BUFFER_SIZE

#define SCP_CLIENT_BUFFER_SIZE   512

Definition at line 54 of file scp_client.h.

◆ SCP_CLIENT_DEFAULT_TIMEOUT

#define SCP_CLIENT_DEFAULT_TIMEOUT   20000

Definition at line 47 of file scp_client.h.

◆ SCP_CLIENT_SUPPORT

#define SCP_CLIENT_SUPPORT   DISABLED

Definition at line 40 of file scp_client.h.

◆ ScpClientContext

#define ScpClientContext   struct _ScpClientContext

Definition at line 61 of file scp_client.h.

Typedef Documentation

◆ ScpClientSshInitCallback

typedef error_t(* ScpClientSshInitCallback) (ScpClientContext *context, SshContext *sshContext)

SSH initialization callback function.

Definition at line 104 of file scp_client.h.

Enumeration Type Documentation

◆ ScpClientState

SCP client state.

Enumerator
SCP_CLIENT_STATE_DISCONNECTED 
SCP_CLIENT_STATE_CONNECTING_1 
SCP_CLIENT_STATE_CONNECTING_2 
SCP_CLIENT_STATE_CONNECTED 
SCP_CLIENT_STATE_CHANNEL_OPEN 
SCP_CLIENT_STATE_CHANNEL_REQUEST 
SCP_CLIENT_STATE_CHANNEL_REPLY 
SCP_CLIENT_STATE_WRITE_INIT 
SCP_CLIENT_STATE_WRITE_COMMAND 
SCP_CLIENT_STATE_WRITE_ACK 
SCP_CLIENT_STATE_WRITE_DATA 
SCP_CLIENT_STATE_WRITE_STATUS 
SCP_CLIENT_STATE_WRITE_FIN 
SCP_CLIENT_STATE_READ_INIT 
SCP_CLIENT_STATE_READ_COMMAND 
SCP_CLIENT_STATE_READ_ACK 
SCP_CLIENT_STATE_READ_DATA 
SCP_CLIENT_STATE_READ_STATUS 
SCP_CLIENT_STATE_READ_FIN 
SCP_CLIENT_STATE_CHANNEL_CLOSE 
SCP_CLIENT_STATE_DISCONNECTING_1 
SCP_CLIENT_STATE_DISCONNECTING_2 

Definition at line 73 of file scp_client.h.

Function Documentation

◆ scpClientBindToInterface()

error_t scpClientBindToInterface ( ScpClientContext context,
NetInterface interface 
)

Bind the SCP client to a particular network interface.

Parameters
[in]contextPointer to the SCP client context
[in]interfaceNetwork interface to be used
Returns
Error code

Definition at line 123 of file scp_client.c.

◆ scpClientClose()

error_t scpClientClose ( ScpClientContext context)

Close the connection with the SCP server.

Parameters
[in]contextPointer to the SCP client context
Returns
Error code

Definition at line 1260 of file scp_client.c.

◆ scpClientCloseFile()

error_t scpClientCloseFile ( ScpClientContext context)

Close file.

Parameters
[in]contextPointer to the SCP client context
Returns
Error code

Definition at line 996 of file scp_client.c.

◆ scpClientConnect()

error_t scpClientConnect ( ScpClientContext context,
const IpAddr serverIpAddr,
uint16_t  serverPort 
)

Establish a connection with the specified SCP server.

Parameters
[in]contextPointer to the SCP client context
[in]serverIpAddrIP address of the SCP server to connect to
[in]serverPortPort number
Returns
Error code

Definition at line 146 of file scp_client.c.

◆ scpClientDeinit()

void scpClientDeinit ( ScpClientContext context)

Release SCP client context.

Parameters
[in]contextPointer to the SCP client context

Definition at line 1281 of file scp_client.c.

◆ scpClientDisconnect()

error_t scpClientDisconnect ( ScpClientContext context)

Gracefully disconnect from the SCP server.

Parameters
[in]contextPointer to the SCP client context
Returns
Error code

Definition at line 1161 of file scp_client.c.

◆ scpClientInit()

error_t scpClientInit ( ScpClientContext context)

Initialize SCP client context.

Parameters
[in]contextPointer to the SCP client context
Returns
Error code

Definition at line 54 of file scp_client.c.

◆ scpClientOpenFileForReading()

error_t scpClientOpenFileForReading ( ScpClientContext context,
const char_t path,
uint64_t *  size 
)

Open a file for reading.

Parameters
[in]contextPointer to the SCP client context
[in]pathPath to the file to be be opened
[out]sizeSize of the file, in bytes (optional parameter)
Returns
Error code

Definition at line 504 of file scp_client.c.

◆ scpClientOpenFileForWriting()

error_t scpClientOpenFileForWriting ( ScpClientContext context,
const char_t path,
uint_t  mode,
uint64_t  size 
)

Open a file for writing.

Parameters
[in]contextPointer to the SCP client context
[in]pathPath to the file to be be opened
[in]modeFile permissions
[in]sizeSize of the file, in bytes
Returns
Error code

Definition at line 239 of file scp_client.c.

◆ scpClientReadFile()

error_t scpClientReadFile ( ScpClientContext context,
void *  data,
size_t  size,
size_t *  received,
uint_t  flags 
)

Read from a remote file.

Parameters
[in]contextPointer to the SCP 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 893 of file scp_client.c.

◆ scpClientRegisterSshInitCallback()

error_t scpClientRegisterSshInitCallback ( ScpClientContext context,
ScpClientSshInitCallback  callback 
)

Register SSH initialization callback function.

Parameters
[in]contextPointer to the SCP client context
[in]callbackSSH initialization callback function
Returns
Error code

Definition at line 80 of file scp_client.c.

◆ scpClientSetTimeout()

error_t scpClientSetTimeout ( ScpClientContext context,
systime_t  timeout 
)

Set communication timeout.

Parameters
[in]contextPointer to the SCP client context
[in]timeoutTimeout value, in milliseconds
Returns
Error code

Definition at line 102 of file scp_client.c.

◆ scpClientWriteFile()

error_t scpClientWriteFile ( ScpClientContext context,
const void *  data,
size_t  length,
size_t *  written,
uint_t  flags 
)

Write to a remote file.

Parameters
[in]contextPointer to the SCP 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 771 of file scp_client.c.