libssh2_sftp_open_ex_r(3)
π libssh2_sftp_open_ex_r β the manual page, but make it make sense π
okay bestie, sit down, hydrate, and let me tell you about the cutest little file-opener in the whole libssh2 family. this is part of the libssh2 manual, and we're talking about libssh2_sftp_open_ex_r(3) β the one with the little _r at the end, which is the reentrant-ish flavor of opening stuff over SFTP. β¨
β¨ NAME β¨
libssh2_sftp_open_ex_r β open filehandle for file on SFTP.
like. it opens a file. over SFTP. and hands you a handle. that's the whole vibe. π«Ά
πΈ SYNOPSIS πΈ
#include <libssh2.h>
#include <libssh2_sftp.h>
LIBSSH2_SFTP_HANDLE *
libssh2_sftp_open_ex_r(LIBSSH2_SFTP *sftp, const char *filename,
size_t filename_len,
unsigned long flags,
long mode,
int open_type,
LIBSSH2_SFTP_ATTRIBUTES *attrs);
no cap, that's a lot of arguments. seven of them. she's high maintenance but she delivers. π
π¦ DESCRIPTION π¦
okay so here's the whole cast of characters, one by one:
sftpβ your SFTP instance, as returned bylibssh2_sftp_init(3). this is your main character, everything happens inside her.filenameβ the remote file/directory resource you wanna open. literally just the path, bestie.filename_lenβ the length offilename. yes, they make you pass it yourself. it's giving old-school C, we move.flagsβ any reasonable combination of theLIBSSH2_FXF_*constants, and ooooh there are options:LIBSSH2_FXF_READβ open the file for reading. πLIBSSH2_FXF_WRITEβ open the file for writing. and 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 in line. π«LIBSSH2_FXF_CREATβ if this flag is specified, then a new file will be created if one does not already exist (and ifLIBSSH2_FXF_TRUNCis specified, the new file will be truncated to zero length if it previously exists).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 listen:LIBSSH2_FXF_CREATMUST also be specified if this flag is used. must. not "should". MUST. periodt.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. same energy.
modeβ the POSIX file permissions to assign if the file is being newly created. peep theLIBSSH2_SFTP_S_*convenience defines in<libssh2_sftp.h>for the sauce. π₯open_typeβ either ofLIBSSH2_SFTP_OPENFILE(to open a file) orLIBSSH2_SFTP_OPENDIR(to open a directory). pick your fighter. β¨attrsβ a pointer to aLIBSSH2_SFTP_ATTRIBUTESstruct. seelibssh2_sftp_fstat_exfor the detailed usage, because she's got lore.
π RETURN VALUE π
a pointer to the newly created LIBSSH2_SFTP_HANDLE instance β yay, iconic, we love her π β or NULL on failure. π (and if you got NULL, go read the errors section, bestie, don't just sit there.)
π ERRORS π
here's the β¨vibe checkβ¨ of things that can go wrong:
LIBSSH2_ERROR_ALLOCβ an internal memory allocation call failed. the malloc said no. πLIBSSH2_ERROR_SOCKET_SENDβ unable to send data on socket.LIBSSH2_ERROR_SOCKET_TIMEOUTβ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. (yes that's "errorcode" as one word, we don't make the rules)LIBSSH2_ERROR_EAGAINβ marked for non-blocking I/O but the call would block. this one is not an L, it's just "try again later", okay? π«Ά
π AVAILABILITY π
added in libssh2 1.11.0. so if you're on something older and it's not linking, that's why. not your fault. iykyk. β
π§ SEE ALSO π§
go read those too, they're the supporting cast and they ate. π
okay that's the whole page!! mwah π this gem was brought to you by libssh2, dated 10 Apr 2023 β so like, bookmark it, screenshot it, send it to the group chat, and go open some files responsibly. no cap, you've got this. πΈπ¦β¨
π¦ 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