Author Topic: Stream from SFTP server  (Read 416 times)

iCorp

  • Posts: 70
Stream from SFTP server
« on: 12 Sep '23 - 12:04 »
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

  • Administrator
  • Posts: 26095
Re: Stream from SFTP server
« Reply #1 on: 12 Sep '23 - 14:05 »
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:

Code: [Select]
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

iCorp

  • Posts: 70
Re: Stream from SFTP server
« Reply #2 on: 12 Sep '23 - 20:56 »
Thank you, Ian!