// ConsoleApplication5.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#import "WinSCPnet32.tlb" raw_interface_only
using namespace WinSCPnet;
int _tmain(int argc, _TCHAR* argv[])
{
HRESULT hr = CoInitialize(NULL);
HRESULT hRet = S_FALSE;
_SessionPtr pSession = NULL;
_SessionOptionsPtr Opt = NULL;
_TransferOptionsPtr TOpt = NULL;
hr = pSession.CreateInstance(_uuidof(Session));
hRet = Opt.CreateInstance(_uuidof(SessionOptions));
Opt->_Protocol = Protocol::Protocol_Sftp;
Opt->HostName = "SomeHost";
Opt->UserName = "root";
Opt->Password = "somepassword";
Opt->GiveUpSecurityAndAcceptAnySshHostKey = VARIANT_TRUE;
if (pSession !=NULL)
{
hr = pSession->Open(Opt);
if (hr == S_OK)
{
hr = TOpt.CreateInstance(__uuidof(TransferOptions));
TOpt->_TransferMode = TransferMode::TransferMode_Binary;
_TransferOperationResultPtr tResult = NULL;
tResult = pSession->GetFiles("/root/*", "c:\\", VARIANT_FALSE, TOpt);
try
{
hr = tResult->Check();
if (hr == S_OK)
{
::printf("GetFiles success");
}
}
catch (_com_error ex)
{
ex.ErrorMessage();
pSession->Close();
}
}
}
CoUninitialize();
return 0;
}
When I call Check(), an Exception with error message "general exception" is found. Check the local drive, some files can be downloaded. May I know what's wrongs of my code. Thanks