libssh2_sftp_open_ex(3)
β¨ libssh2_sftp_open_ex(3) β¨
okay bestie, welcome to the libssh2 manual page for libssh2_sftp_open_ex π pull up a chair, grab a strawberry π, we're opening filehandles today and honestly? iconic behaviour.
πΈ NAME πΈ
libssh2_sftp_open_ex β open a filehandle for a file on SFTP. that's it, that's the whole vibe. it's giving "let me in" π
π¦ SYNOPSIS π¦
#include <libssh2.h>
#include <libssh2_sftp.h>
LIBSSH2_SFTP_HANDLE *
libssh2_sftp_open_ex(LIBSSH2_SFTP *sftp, const char *filename,
unsigned int filename_len,
unsigned long flags,
long mode,
int open_type);
look at her. six arguments. she's a handful and we love her for it ππ«Ά
β¨ DESCRIPTION β¨
let's go arg by arg, no cap, because every single one matters:
sftpβ the SFTP instance you already got back fromlibssh2_sftp_init(3). your main character. your ride or die.filenameβ the remote file/directory resource you wanna open. remote, bestie. we're not on your laptop rn πfilename_lenβ the length offilename. yes you have to say it out loud. she doesn't measure for you, that's just her vibe.flagsβ any reasonable combination of theLIBSSH2_FXF_*constants, listed below in full because we don't skip:LIBSSH2_FXF_READβ open the file for reading. just reading. a lil peek πLIBSSH2_FXF_WRITEβ open the file for writing. and listen: if you specify both this andLIBSSH2_FXF_READ, the file gets opened for both reading and writing. multitasking queen πLIBSSH2_FXF_APPENDβ force all writes to append data at the end of the file. no cutting the line, everyone goes to the back πLIBSSH2_FXF_CREAT,β if this flag is specified, then a new file will be created if one does not already exist (ifLIBSSH2_FXF_TRUNCis specified, the new file will be truncated to zero length if it previously exists). brand new file, fresh start, glow up π±LIBSSH2_FXF_TRUNCβ forces an existing file with the same name to be truncated to zero length when creating a file by specifyingLIBSSH2_FXF_CREAT. and heads up:LIBSSH2_FXF_CREATMUST also be specified if this flag is used. noCREAT, noTRUNC, that's the rule π’LIBSSH2_FXF_EXCLβ causes the request to fail if the named file already exists. and again:LIBSSH2_FXF_CREATMUST also be specified if this flag is used. she's exclusive, literally π
modeβ POSIX file permissions to assign if the file is being newly created. see theLIBSSH2_SFTP_S_*convenience defines in<libssh2_sftp.h>. only kicks in for fresh files, so don't stress about it otherwise β¨open_typeβ either ofLIBSSH2_SFTP_OPENFILE(to open a file) orLIBSSH2_SFTP_OPENDIR(to open a directory). pick your fighter: file or folder, no in-between π¦
π₯ RETURN VALUE π₯
a pointer to the newly created LIBSSH2_SFTP_HANDLE instance π or NULL on failure π. that's the whole story.
π ERRORS π
here's the drama list, every single one, no skipping:
LIBSSH2_ERROR_ALLOCβ an internal memory allocation call failed.LIBSSH2_ERROR_SOCKET_SENDβ unable to send data on socket.LIBSSH2_ERROR_SOCKET_TIMEOUTβ (yes, that's genuinely all it says. mysterious. we stan a cryptic icon π)LIBSSH2_ERROR_SFTP_PROTOCOLβ an invalid SFTP protocol response was received on the socket, or an SFTP operation caused an errorcode to be returned by the server.LIBSSH2_ERROR_EAGAINβ marked for non-blocking I/O but the call would block.
real talk bestie: if you see LIBSSH2_ERROR_EAGAIN on a non-blocking setup, that is not the end of the world, it's just her saying "not right now, try again later" π
π SEE ALSO π
libssh2_sftp_close_handle(3)β because you gotta close what you open, periodt π«Ά
and that's the page, bestie!! this was the libssh2 manual, version 0.15, dated 1 Jun 2007 β yes she's vintage, she's a classic, she ate and left no crumbs πβ¨ go forth and open those filehandles, you absolute legend π
π
π¦ where this page comes from
- alpine 3.22: libssh2-doc 1.11.1-r3 Β· BSD-3-Clause
- alpine 3.23: libssh2-doc 1.11.1-r4 Β· BSD-3-Clause
- alpine 3.24: libssh2-doc 1.11.1-r4 Β· BSD-3-Clause
- arch rolling: libssh2 1.11.1-7 Β· BSD-3-Clause
- debian trixie: libssh2-1-dev 1.11.1-1+deb13u1 Β· BSD3
- debian trixie: libssh2-1-dev 1.11.1-1+deb13u2 Β· BSD3
- epel 10: libssh2-docs 1.11.1-9.el10_3 Β· BSD-3-Clause
- epel 9: libssh2-docs 1.11.1-9.el9 Β· BSD-3-Clause
- fedora 43: libssh2-docs 1.11.1-4.fc43 Β· BSD-3-Clause
- fedora 43: libssh2-docs 1.11.1-9.fc43 Β· BSD-3-Clause
- fedora 44: libssh2-docs 1.11.1-5.fc44 Β· BSD-3-Clause
- fedora 44: libssh2-docs 1.11.1-9.fc44 Β· BSD-3-Clause
- opensuse-leap 16.0: libssh2-devel 1.11.1-160000.5.1 Β· BSD-3-Clause
- opensuse-leap 16.0: libssh2-devel 1.11.1-160000.5.1 Β· BSD-3-Clause
- opensuse-leap 16.0: libssh2-devel 1.11.1-160000.5.1 Β· BSD-3-Clause
- opensuse-leap 16.0: libssh2-devel 1.11.1-160000.5.1 Β· BSD-3-Clause
- ubuntu questing: libssh2-1-dev 1.11.1-1build1
- ubuntu questing: libssh2-1-dev 1.11.1-1ubuntu0.25.10.2
- ubuntu resolute: libssh2-1-dev 1.11.1-1build2 Β· BSD3
- ubuntu resolute: libssh2-1-dev 1.11.1-1ubuntu0.26.04.4 Β· BSD3
- ubuntu stonking: libssh2-1-dev 1.11.1-6 Β· BSD3
- π the page's license: BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms