Stream from SFTP server

Started by iCorp,

iCorp

Hello,

Are there any examples available for streaming data from an SFTP server directly or using third-party libraries?
I'm open to examples in any programming language, but I would prefer examples in C# if possible.
Thank you.

Ian @ un4seen

BASS doesn't include built-in SFTP support, but you can add support via BASS_StreamCreateFileUser with the help of a third-party library, something like this:

void CALLBACK MyFileCloseProc(void *user)
{
DownloadStuff *download = (DownloadStuff*)user;
download->Close();
}

QWORD CALLBACK MyFileLenProc(void *user)
{
DownloadStuff *download = (DownloadStuff*)user;
return download->GetLength();
}

DWORD CALLBACK MyFileReadProc(void *buffer, DWORD length, void *user)
{
DownloadStuff *download = (DownloadStuff*)user;
return download->Read(buffer, length);
}

...

DownloadStuff *download = ...; // open connection here
BASS_FILEPROCS fileprocs = { MyFileCloseProc, MyFileLenProc, MyFileReadProc, NULL };
stream = BASS_StreamCreateFileUser(STREAMFILE_BUFFER, 0, &fileprocs, download);

How you implement the "DownloadStuff" will depend on what library you use. I've never tried this with SFTP myself, so I can't give any specific examples, but I believe libcurl is generally a popular choice and includes SFTP support:

   https://curl.se/libcurl/

It looks like another option specifically for .Net is SSH.NET:

   https://github.com/sshnet/SSH.NET