TrustCore SDK NanoSSH API reference  version 7.0
SFTP Server Context State Management Functions

Functions

MOC_EXTERN void * SSH_sftpGetCookie (void *sftpInternelDescr)
 Get a connection's cookie (containing custom information). More...
 
MOC_EXTERN void SSH_sftpSetCookie (void *sftpInternelDescr, void *sftpCookie)
 Save a cookie containing custom information about a context connection. More...
 

Detailed Description

Function Documentation

◆ SSH_sftpGetCookie()

MOC_EXTERN void* SSH_sftpGetCookie ( void *  sftpInternelDescr)

This function gets a cookie containing custom information about a context connection. Your application should call this function after calls to SSH_sftpSetCookie(), or to make custom SFTP upcalls.

Since
1.41
Version
1.41 and later

To enable this function, the following flags must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_SERVER__
  • __ENABLE_MOCANA_SSH_FTP_SERVER__

sftp.h

Parameters
sftpInternelDescrState information for a specific open file connection (similar to a connection instance).
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.
Remarks
This function is applicable to synchronous SFTP servers.
See also
SSH_sftpSetCookie
static void
SFTP_EXAMPLE_closeUpcall(sbyte4 connectionInstance,
sbyte4 sftpInternelDescr)
{
fclose((FILE *)SSH_sftpGetCookie(sftpInternelDescr));
}

ssh_ftp.c

◆ SSH_sftpSetCookie()

MOC_EXTERN void SSH_sftpSetCookie ( void *  sftpInternelDescr,
void *  sftpCookie 
)

This function saves a cookie containing custom information about a context connection.

Since
1.41
Version
1.41 and later

To enable this function, the following flags must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_SERVER__
  • __ENABLE_MOCANA_SSH_FTP_SERVER__

sftp.h

Parameters
sftpInternelDescrState information for a desired open file connection (similar to a connection instance).
sftpCookieCookie data (custom information).
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.
Remarks
This function is applicable to synchronous SFTP servers.
See also
SSH_sftpGetCookie
static sbyte4
SFTP_EXAMPLE_openUpcall(sbyte4 connectionInstance,
sbyte4 sftpInternelDescr,
ubyte *pLongPath,
ubyte *pFilename,
sbyte4 flags)
{
FILE* fd = 0;
ubyte* pFileFlags;
ubyte* pFullPath = NULL;
sbyte4 status = SSH_FTP_OK;
// setup fopen file flag string
if (flags & SFTP_OPEN_FILE_READ_BINARY)
pFileFlags = "rb";
else if (flags & SFTP_OPEN_FILE_WRITE_BINARY)
pFileFlags = "wb";
else {
status = SSH_FTP_PERMISSION_DENIED;
goto exit;
}
// open the file handle
if (NULL != (pFullPath = createPathName(pLongPath, pFilename)))
fd = fopen(pFullPath, pFileFlags);
if (!fd)
status = SSH_FTP_FAILURE;
SSH_sftpSetCookie(sftpInternelDescr, (sbyte4)fd);
exit:
if (NULL != pFullPath)
free(pFullPath);
return status;
}

ssh_ftp.c