Subject: Re: Running example sftp_write.c results in error 2, LIBSSH2_FX_NO_SUCH_FILE

Re: Running example sftp_write.c results in error 2, LIBSSH2_FX_NO_SUCH_FILE

From: Peter Stuge <>
Date: Sat, 17 Oct 2020 10:37:39 +0000

Michael Loutris wrote:
> All the libssh2 calls return success until libssh2_sftp_open(), where the
> sftp handle is returned NULL.
> Calling libssh2_sftp_last_error() returns error 2, LIBSSH2_FX_NO_SUCH_FILE.
> The flags and mode were left with the defaults:
> sftp_handle = libssh2_sftp_open(sftp_session, sftppath,
> As OpenSSH commands in a Windows command prompt succeeded in
> writing to the server, what settings might I be missing in libssh2?

Without a debug log (from the server) it's impossible to say what went
wrong. This is obvious, right? So we can only guess, which is not very
effective problem solving.

Since you're using Windows my guess is that the error is related to the
path that you have specified rather than the filename in the final

Every directory in the path must exist and you must use forward slash as
the directory separator in the SFTP protocol, never the Windows backslash.

OpenSSH built by Microsoft for Windows will possibly hide that for
your convenience, which would make it seem that the protocol accepts
different directory separators, but if my guess is correct then that's
essentially just Microsoft lying to you.

Received on 2020-10-17