Using Session.PutFile() with stream, returns error Operation not supported

Advertisement

nikolasd
Joined:
Posts:
2
Location:
Greece

Using Session.PutFile() with stream, returns error Operation not supported

I am using the latest RC release of WinSCP NuGet package and I am trying to implement PutFile
using (var session = new Session()) {
    if (!session.Opened)
        session.Open(sessionOptions);
 
    var transferOptions = new TransferOptions {
        TransferMode = TransferMode.Binary,
        OverwriteMode = OverwriteMode.Overwrite,   
    };
 
    using (var stream = new MemoryStream(imgData)) {
        session.PutFile(stream, remoteFilePath, transferOptions);
    }
}
session.PutFile throws exception with error message
Operation not supported.
What can be the issue that is causing this error?

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,504
Location:
Prague, Czechia

Re: Using Session.PutFile() with stream, returns error Operation not supported

What protocol are you using? The streaming is supported with the SFTP protocol only. With other protocols, you need to save the data to (temporary) file before uploading.

Reply with quote

Advertisement

juhl
Guest

Re: Stream File With FTP

Hi Martin

I'm trying out the new stream method, and the GetFile seems to work.
But to get the content of the Stream (I use MemoryStream), I do a Position = 0, to get to the start of the stream, but this operation is not supported.

Any good ideas? :-)

Reply with quote

juhl
Guest

Re: Stream File With FTP

Hi Martin

Code: (not C# syntax but .NET code)
FtpSessionOptions := FtpSessionOptions.SessionOptions;
FtpSessionOptions.Protocol := FtpProtocol.Ftp;
FtpSessionOptions.HostName := Host;
FtpSessionOptions.UserName := Username;
FtpSessionOptions.Password := Password;
FtpSessionOptions.FtpSecure := FtpSecure.Explicit;
FtpSessionOptions.GiveUpSecurityAndAcceptAnyTlsHostCertificate := TRUE;
 
FtpSession := FtpSession.Session;
FtpSession.ExecutablePath(ExePath);
FtpSession.Open(FtpSessionOptions);
 
MemoryStream := FtpSession.GetFile(Path, FtpTransferOptions);
MemoryStream.Position := 0; // Gives the error
Error is:
WinSCP.PipeStream.Position failed: Specified method is not supported.
I need to seek back to get the file data from MemoryStream.

Reply with quote

martin
Site Admin
martin avatar

Re: Stream File With FTP

Your code makes no sense. First, the Session.GetFile does not return MemoryStream. It returns a custom implementation of the Stream interface. And it indeed does not implement a writable Position property.
Second, the returned stream is at the beginning. There's no need to seek it.

Reply with quote

Advertisement

test12
Guest

session.PutFile throwing error saying operation not supported

I am using WinSCP 6.1.1 version but still streaming with FTP isn't working as session.PutFile is throwing error saying "operation not supported".

Reply with quote

martin
Site Admin
martin avatar

Re: session.PutFile throwing error saying operation not supported

@test12: Please post debug and session logs – Session.SessionLogPath and Sessionm.DebugLogPath.

Reply with quote

Advertisement

You can post new topics in this forum