Jump to content


Photo

Legacy replacement functions


  • Please log in to reply
3 replies to this topic

#1 Richard_B

Richard_B
  • Members
  • 24 posts

Posted 26 September 2010 - 03: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

#2 mb

mb

    Developer

  • Administrators
  • 11521 posts
  • Gender:
    Male
  • Location:
    Worldwide

Posted 26 September 2010 - 05: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.

#3 Richard_B

Richard_B
  • Members
  • 24 posts

Posted 26 September 2010 - 06: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;
}

}

#4 mb

mb

    Developer

  • Administrators
  • 11521 posts
  • Gender:
    Male
  • Location:
    Worldwide

Posted 09 December 2010 - 03: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:
http://www.smartftp.com/features/sdk/

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users