# Ne7SftpSubsystem Class Reference

`#include <ne7ssh.h>`

Collaboration diagram for Ne7SftpSubsystem:

[legend]

List of all members.

## Classes
struct | fileAttrs
## Public Types
enum | writeMode { READ, OVERWRITE, APPEND }
## Public Member Functions
| Ne7SftpSubsystem ()
| Ne7SftpSubsystem (class Ne7sshSftp *_sftp)
| ~Ne7SftpSubsystem ()
bool | setTimeout (uint32 _timeout)
uint32 | openFile (const char *filename, uint8 mode)
uint32 | openDir (const char *dirname)
bool | readFile (uint32 fileID, uint64 offset=0)
bool | writeFile (uint32 fileID, const uint8 *data, uint32 len, uint64 offset=0)
bool | closeFile (uint32 fileID)
bool | getFileAttrs (fileAttrs &attrs, const char *filename, bool followSymLinks=true)
bool | get (const char *remoteFile, FILE *localFile)
bool | put (FILE *localFile, const char *remoteFile)
bool | rm (const char *remoteFile)
bool | mv (const char *oldFile, const char *newFile)
bool | mkdir (const char *remoteDir)
bool | rmdir (const char *remoteDir)
const char * | ls (const char *remoteDir, bool longNames=false)
bool | cd (const char *remoteDir)
bool | chmod (const char *remoteFile, const char *mode)
bool | chown (const char *remoteFile, uint32_t uid, uint32_t gid=0)
bool | isFile (const char *remoteFile)
bool | isDir (const char *remoteFile)
## Private Member Functions
bool | errorNotInited ()
## Private Attributes
bool | inited
Ne7sshSftp * | sftp

## Detailed Description

Author:
  Andrew Useckas <andrew@netsieben.com>

## Member Enumeration Documentation

enum Ne7SftpSubsystem::writeMode

Modes used when opening a remote file.

## Constructor & Destructor Documentation

Ne7SftpSubsystem::Ne7SftpSubsystem | ( |  | ) |

Default constructor.

Ne7SftpSubsystem::Ne7SftpSubsystem | ( | class Ne7sshSftp * | _sftp | ) |

Constructor used to initialize the subsystem with a new Ne7sshSftp class instance.

Parameters:

  | _sftp | Ne7sshSftp class instance.

Ne7SftpSubsystem::~Ne7SftpSubsystem | ( |  | ) |

Default destructor.

## Member Function Documentation

bool Ne7SftpSubsystem::cd | ( | const char * | remoteDir | ) |

This method is used to change the current working directory.

Parameters:

  | remoteDir | Full or relative path to the new working directory on the remote server.

Returns:
  True if change of directory succedded. False on any error.

References Ne7sshSftp::cd(), and errorNotInited().

bool Ne7SftpSubsystem::chmod | ( | const char * | remoteFile,
|  | const char * | mode |
| ) |  |  |

This method is used for changing the permissions associated with a remote file.

Parameters:

  | remoteFile | Full or relative path to the remote file.
  | mode | Mode string. It can be either a numerical mode expression such as "755" or an expression showing the modifications to be made, such as "ug+w". Mode string is the same as used by *nix chmod command.

Returns:
  True if the new permissions are succesfully applied to the remote file. False on any error.

References Ne7sshSftp::chmod(), and errorNotInited().

bool Ne7SftpSubsystem::chown | ( | const char * | remoteFile,
|  | uint32_t | uid,
|  | uint32_t | gid = `0` |
| ) |  |  |

This method is used to change the owner of a remote file.

Parameters:

  | remoteFile | Full or relative path to the remote file.
  | uid | Numerical new owner user ID.
  | gid | Numerical new owner group ID.

Returns:
  True if the change of ownership succeeds. False on any error.

References Ne7sshSftp::chown(), and errorNotInited().

bool Ne7SftpSubsystem::closeFile | ( | uint32 | fileID | ) |

Low level method used to close a file opened by using openFile() method.

Parameters:

  | fileID | File ID returned by openFile() method.

Returns:
  True on success. False on any error.

References Ne7sshSftp::closeFile(), and errorNotInited().

bool Ne7SftpSubsystem::errorNotInited | ( |  | ) | `[private]`

Pushes and error to the error buffer, if this subsystem has not been initialized before usage.

Returns:
  True if the push succeeds. Otherwise false.

References ne7ssh::errors(), and Ne7sshError::push().

Referenced by cd(), chmod(), chown(), closeFile(), get(), getFileAttrs(), isDir(), isFile(), ls(), mkdir(), mv(), openDir(), openFile(), put(), readFile(), rm(), rmdir(), setTimeout(), and writeFile().

bool Ne7SftpSubsystem::get | ( | const char * | remoteFile,
|  | FILE * | localFile |
| ) |  |  |

This method is used to retrieve a remote file and dump it into local file.

Parameters:

  | remoteFile | Full or relative path to the file on the remote side.
  | localFile | Pointer to the FILE structure. If the file being retrieved is binary, use "w+" attributes in fopen function.

Returns:
  True if getting the file is succeeds. False on any error.

References errorNotInited(), and Ne7sshSftp::get().

bool Ne7SftpSubsystem::getFileAttrs | ( | fileAttrs & | attrs,
|  | const char * | filename,
|  | bool | followSymLinks = `true` |
| ) |  |  |

This method is used to retrieve remote file attributes and place them into fileAttrs structure.

Parameters:

  | attrs | Reference to fileAttrs structure where retrieved attributes should be placed.
  | filename | Name of the remote file.
  | followSymLinks | If this variable is set to true, symbolic links will be followed. That is the default befavour. If this behavour is undesired, pass "false".

Returns:
  True if the attributes successfully retrieved. Otherwise false is returned.

References errorNotInited(), and Ne7sshSftp::getFileAttrs().

bool Ne7SftpSubsystem::isDir | ( | const char * | remoteFile | ) |

This method is used to determine if a remote inode is a directory.

Parameters:

  | remoteFile | Full or relative path to the remote file.

Returns:
  True if the remote inode is a directory. Otherwise false.

References errorNotInited(), and Ne7sshSftp::isDir().

bool Ne7SftpSubsystem::isFile | ( | const char * | remoteFile | ) |

This method is used to determine if a remote inode is a regular file.

Parameters:

  | remoteFile | Full or relative path to the remote inode.

Returns:
  True if the remote inode is a regular file. Otherwise false.

References errorNotInited(), and Ne7sshSftp::isFile().

const char * Ne7SftpSubsystem::ls | ( | const char * | remoteDir,
|  | bool | longNames = `false` |
| ) |  |  |

This methods is used retrieve a listing of a remote directory.

Parameters:

  | remoteDir | Full or relative path to a directory.
  | longNames | If set to "true" the returned string in addition to file strings will contain attributes for each file.

Returns:
  A pointer to a string containing the directory listing.

References errorNotInited(), and Ne7sshSftp::ls().

bool Ne7SftpSubsystem::mkdir | ( | const char * | remoteDir | ) |

This method is used to create a new directory.

Parameters:

  | remoteDir | Full or relative path to a new directory on the remote server.

Returns:
  True if the directory successfully created. False on any error.

References errorNotInited(), and Ne7sshSftp::mkdir().

bool Ne7SftpSubsystem::mv | ( | const char * | oldFile,
|  | const char * | newFile |
| ) |  |  |

This method is used to rename/move files.

Parameters:

  | oldFile | Full or relative path to an old file on the remote server.
  | newFile | Full or relative path to a new file on the remote side.

Returns:
  True if renaming successfull. False on any error.

References errorNotInited(), and Ne7sshSftp::mv().

uint32 Ne7SftpSubsystem::openDir | ( | const char * | dirname | ) |

Low level method used to open an inode containing file entries a.k.a directory.

Parameters:

  | dirname | Relative or full path to the inode.

Returns:
  Newly opened file ID or 0 if the inode could not be opened.

References errorNotInited(), and Ne7sshSftp::openDir().

uint32 Ne7SftpSubsystem::openFile | ( | const char * | filename,
|  | uint8 | mode |
| ) |  |  |

Low level method used to open a remote file.

Parameters:

  | filename | Relative or full path to the file.
  | mode | Mode to be used when opening the file. Can be one of the modes defined by writeMode class variable.

Returns:
  Newly opened file ID or 0 if file could not be opened.

References errorNotInited(), and Ne7sshSftp::openFile().

bool Ne7SftpSubsystem::put | ( | FILE * | localFile,
|  | const char * | remoteFile |
| ) |  |  |

This method is used to upload a file to a remote server.

Parameters:

  | localFile | Pointer to the FILE structure. If the file being retrieved is binary, use "r+" attributes in fopen function.
  | remoteFile | Full or relative path to the file on the remote side.

Returns:
  True if putting the file succeeds. False on any error.

References errorNotInited(), and Ne7sshSftp::put().

bool Ne7SftpSubsystem::readFile | ( | uint32 | fileID,
|  | uint64 | offset = `0` |
| ) |  |  |

Low level method used to read datablock up to the size of SFTP_MAX_MSG_SIZE from a file.

Parameters:

  | fileID | File ID retruned by openFile() method.
  | offset | Offset.

Returns:
  True if file content successfully read and placed in the buffer. Otherwise false.

References errorNotInited(), and Ne7sshSftp::readFile().

bool Ne7SftpSubsystem::rm | ( | const char * | remoteFile | ) |

This method is used to remove a file on a remote server.

Parameters:

  | remoteFile | Full or relative path to the file on the remote side.

Returns:
  True if remove succeeds. False on any error.

References errorNotInited(), and Ne7sshSftp::rm().

bool Ne7SftpSubsystem::rmdir | ( | const char * | remoteDir | ) |

This method is used to remove a remote directory.

Parameters:

  | remoteDir | Full or relative path to a directory to be removed.

Returns:
  True if the directory successfully removed. False on any error.

References errorNotInited(), and Ne7sshSftp::rmdir().

bool Ne7SftpSubsystem::setTimeout | ( | uint32 | _timeout | ) |

This method is used to set a timeout for all SFTP subsystem communications.

Parameters:

  | _timeout | Timeout in seconds.

Returns:
  True if timeout set, otherwise false.

References errorNotInited(), and Ne7sshSftp::setTimeout().

bool Ne7SftpSubsystem::writeFile | ( | uint32 | fileID,
|  | const uint8 * | data,
|  | uint32 | len,
|  | uint64 | offset = `0` |
| ) |  |  |

Low level method used to write data-block up to the size of SFTP_MAX_MSG_SIZE to a remote file.

Parameters:

  | fileID | File ID returned by openFile() method.
  | data | Pointer to a buffer containing the data.
  | len | Length of the block.
  | offset | Offset in the remote file. If offset is passed EOF the space between EOF and offset will be filled by 0x0.

Returns:
  True if file contect successfully written. False on any error.

References errorNotInited(), and Ne7sshSftp::writeFile().

The documentation for this class was generated from the following files:

- ne7ssh.h
- ne7ssh.cpp