ssh2.sftp¶
SFTP channel class and related SFTP flags.
File types¶
- var LIBSSH2_SFTP_S_IFMT
Type of file mask
- var LIBSSH2_SFTP_S_IFIFO
Named pipe (fifo)
- var LIBSSH2_SFTP_S_IFCHR
Character special (character device)
- var LIBSSH2_SFTP_S_IFDIR
Directory
- var LIBSSH2_SFTP_S_IFBLK
Block special (block device)
- var LIBSSH2_SFTP_S_IFREG
Regular file
- var LIBSSH2_SFTP_S_IFLNK
Symbolic link
- var LIBSSH2_SFTP_S_IFSOCK
Socket
File transfer flags¶
- var LIBSSH2_FXF_READ
File read flag
- var LIBSSH2_FXF_WRITE
File write flag
- var LIBSSH2_FXF_APPEND
File append flag
- var LIBSSH2_FXF_CREAT
File create flag
- var LIBSSH2_FXF_TRUNC
File truncate flag
- var LIBSSH2_FXF_EXCL
Exclusive file flag
File mode masks¶
Owner masks¶
- var LIBSSH2_SFTP_S_IRWXU
Read/write/execute
- var LIBSSH2_SFTP_S_IRUSR
Read
- var LIBSSH2_SFTP_S_IWUSR
Write
- var LIBSSH2_SFTP_S_IXUSR
Execute
Group masks¶
- var LIBSSH2_SFTP_S_IRWXG
Read/write/execute
- var LIBSSH2_SFTP_S_IRGRP
Read
- var LIBSSH2_SFTP_S_IWUSR
Write
- var LIBSSH2_SFTP_S_IXUSR
Execute
Other masks¶
- var LIBSSH2_SFTP_S_IRWXO
Read/write/execute
- var LIBSSH2_SFTP_S_IROTH
Read
- var LIBSSH2_SFTP_S_IWOTH
Write
- var LIBSSH2_SFTP_S_IXOTH
Execute
Generic mode masks¶
- var LIBSSH2_SFTP_ST_RDONLY
Read only
- var LIBSSH2_SFTP_ST_NOSUID
No suid
-
class
ssh2.sftp.
SFTP
¶ SFTP session.
- Parameters
session (
ssh2.session.Session
pointer) – Session that initiated SFTP.
-
get_channel
(self)¶ Get new channel from the SFTP session
-
lstat
(self, path)¶ Link stat a file.
-
mkdir
(self, path, long mode)¶ Make directory.
- Parameters
- Return type
- Raises
Appropriate exception from
ssh2.exceptions
on errors.
-
open
(self, filename, unsigned long flags, long mode)¶ Open file handle for file name.
- Parameters
filename (str) – Name of file to open.
flags (int) –
One or more LIBSSH2_FXF_* flags.
Eg for reading flags is
LIBSSH2_FXF_READ
,for writing
LIBSSH2_FXF_WRITE
,for both
LIBSSH2_FXF_READ
|LIBSSH2_FXF_WRITE
.mode (int) –
File permissions mode.
LIBSSH2_SFTP_S_IRUSR
for reading.For writing one or more
LIBSSH2_SFTP_S_*
flags.Eg, for 664 permission mask (read/write owner/group, read other),
mode is
LIBSSH2_SFTP_S_IRUSR | LIBSSH2_SFTP_S_IWUSR | \
LIBSSH2_SFTP_S_IRGRP | LIBSSH2_SFTP_S_IWGRP | \
LIBSSH2_SFTP_S_IROTH
- Raises
ssh2.exceptions.SFTPHandleError
on errors opening file.
-
open_ex
(self, const char *filename, unsigned int filename_len, unsigned long flags, long mode, int open_type)¶
-
opendir
(self, path)¶ Open handle to directory path.
- Parameters
path (str) – Path of directory
- Return type
ssh2.sftp.SFTPHandle
or None- Raises
ssh2.exceptions.SFTPHandleError
on errors opening directory.
-
realpath
(self, path, size_t max_len=256)¶ Get real path for path.
- Param
Path name to get real path for.
- Parameters
max_len (int) – Max size of returned real path.
- Raises
ssh2.exceptions.SFTPHandleError
on errors getting real path.- Raises
ssh2.exceptions.SFTPBufferTooSmall
on max_len less than real path length.
-
rename
(self, source_filename, dest_filename)¶ Rename file.
-
rename_ex
(self, const char *source_filename, unsigned int source_filename_len, const char *dest_filename, unsigned int dest_filename_len, long flags)¶
-
rmdir
(self, path)¶ Remove directory.
-
setstat
(self, path, SFTPAttributes attrs)¶ Set file attributes.
- Parameters
path (str) – File path.
attrs (
ssh2.sftp_handle.SFTPAttributes
) – File attributes to set.
- Return type
-
stat
(self, path)¶ Stat file.
- Parameters
path (str) – Path of file to stat.
- Return type
ssh2.sftp_handle.SFTPAttributes
or LIBSSH2_ERROR_EAGAIN
-
statvfs
(self, path)¶ Get file system statistics from path.
- Return type
ssh2.sftp.SFTPStatVFS or int of error code
-
symlink
(self, path, target)¶ Create symlink.
-
unlink
(self, filename)¶ Delete/unlink file.
- Parameters
filename (str) – Name of file to delete/unlink.
-
session
¶ Originating session.