Legacy replacement functions

This forum is not monitored by the SmartFTP staff. If you have a license please contact technical support by email.
Post Reply
RBygrave
Posts: 24
Joined: Mon Jan 14, 2008 8:36 pm

Legacy replacement functions

Post by RBygrave » Sun Sep 26, 2010 3:42 pm

I have run into some other issues while upgradig some of our legacy code.

I used to do stream based operations rather than direct file IO.

Here is a snipit of the original code

public MemoryStream GetFile(string _fileName)
{
MemoryStream IN_Stream = new MemoryStream();
ftpIN.CloseStreamsAfterTransfer = false;
ftpIN.DownloadStream(IN_Stream, _fileName);
return IN_Stream
}

In the new libary I don't see the replacements for the stream operations. What would be the replacement functions for this?

Thanks in advance

mb
Posts: 12030
Joined: Thu Oct 11, 2001 1:24 pm
Display name: Mat (SmartFTP)
Contact:

Re: Legacy replacement functions

Post by mb » Sun Sep 26, 2010 5:25 pm

You may want to look at the following function:
HRESULT DownloadFileEx(
[in] BSTR bstrRemoteFile,
[in] VARIANT varLocalFile,
[in] long nRemoteStartPosLo,
[in] long nRemoteStartPosHi,
[in] long nLocalStartPosLo,
[in] long nLocalStartPosHi,
[out, retval] enumError * retval

varLocalFile
An indicator of the local file. This may be a path to a file (String/BSTR), an IStream or any object that supports IStream.

RBygrave
Posts: 24
Joined: Mon Jan 14, 2008 8:36 pm

Re: Legacy replacement functions

Post by RBygrave » Sun Sep 26, 2010 6:36 pm

I have re-written it like this, will see if it works on monday.

public MemoryStream GetFile(string fileName)
{
if (_Status != (int)Stat.OPEN)
{
_LastMessage = "Connection not open";
return null;
}
int nStartPosLo = 0,rStartPosLo = 0 ;
int nStartPosHi = 0, rStartPosHi = 0;
MemoryStream _strm = new MemoryStream();
_ftp.DataTransferMode = enumDataTransferMode.ftpDataTransferModeStream;
_ftp.DataProtection = enumDataProtection.ftpDataProtectionPrivate;
_ftp.DataTransferType = enumDataTransferType.ftpDataTransferTypeASCII;

err = _ftp.Download(fileName, (object)_strm, rStartPosLo, rStartPosHi, nStartPosLo, nStartPosHi);
if ( err == enumError.ftpErrorSuccess)
{
_strm.Seek(0, System.IO.SeekOrigin.Begin);
return _strm;
}
else
{
_LastMessage = MapError(err);
return null;
}

}

mb
Posts: 12030
Joined: Thu Oct 11, 2001 1:24 pm
Display name: Mat (SmartFTP)
Contact:

Re: Legacy replacement functions

Post by mb » Thu Dec 09, 2010 3:35 am

That won't work because the C# Stream class does not implement the COM IStream interface. What you need is a IStream to C# Stream adapter. You can find one in the SmartFTP SDK:
https://www.smartftp.com/client/features/sdk

The adapter is located at Samples\TransferQueue\C#\Download\Interop\IStreamAdapater.cs

Post Reply