C++(MFC) SFTP with PrivateKey - WeOnlyDo Discussion board

C++(MFC) SFTP with PrivateKey (wodSFTP / wodSFTP.NET / wodSFTPdll)

by OMOR, Thursday, July 20, 2006, 15:44 (6701 days ago)

Hi

I want to use wodFtpDlx to connect to a server with SFTP protocol and public/private keys. I followed the Getting Started in VC in wodFtpDLX.pdf, but now I'm stuck. I see that I need a Certificate, but how do I create that, and how do I link it to IwodFtpDLXCom?

Omor

Re: C++(MFC) SFTP with PrivateKey

by wodDrazen, Thursday, July 20, 2006, 15:54 (6701 days ago) @ OMOR

Hi Omor,


More help how to connect to server with PrivateKey using wodFtpDLX ActiveX component you can find here:

http://www.weonlydo.com/index.asp?kb=1&View=entry&CategoryID=9&EntryID=50

Hope this helps.


Regards,
Drazen

Re: C++(MFC) SFTP with PrivateKey

by wodSupport, Thursday, July 20, 2006, 16:02 (6701 days ago) @ wodDrazen

OMOR,

just as 'WeOnlyDo.wodFtpDLXCom.1' is initalized in your code, you need to initialize 'WeOnlyDo.Certificate.1' too. You will need to import it the same way as you imported wodFtpDLXCom.

When you initalize it, call GenerateKey and Generate to generate key and certificate, set it to Certificate property etc..

Can you try that?

Regards,
Kreso

Re: C++(MFC) SFTP with PrivateKey

by OMOR, Friday, July 21, 2006, 08:13 (6701 days ago) @ wodSupport

Thanks
It helped a little bit, but I can still not see how to link my certificate to IwodFtpDLXCom. I dont see any SetCertificate function (but a GetCertificate). Is it my autogenerated wrapper class that is buggy?

Re: C++(MFC) SFTP with PrivateKey

by wodDamir, Friday, July 21, 2006, 08:51 (6701 days ago) @ OMOR

Hi OMOR,

you can use wodCertificate's LoadKey Method to load private key from file.

Regards,
Damir

Re: C++(MFC) SFTP with PrivateKey

by OMOR, Friday, July 21, 2006, 09:17 (6701 days ago) @ wodDamir

Sorry if I wasnt clear enough...

I have created an instance of IwodFtpDLXCom and ICertificate, but when I see the VB code wodDrazen link to:

[code]
Set ftp1 = New wodFtpDLXCom
Set cert = New Certificate
Set ftp1.Certificate = cert

cert.LoadKey c:RSAprivate.txt , weonlydo

ftp1.HostName = your_hostname
ftp1.Authentication = authCertificate
ftp1.Login = your_login
ftp1.Protocol = SFTP
ftp1.Connect
[/code]

The Certificate is connected with wodFtpDLXCom:
[code]Set ftp1.Certificate = cert[/code]
How do I do that in VC?

Re: C++(MFC) SFTP with PrivateKey

by wodSupport, Friday, July 21, 2006, 19:13 (6700 days ago) @ OMOR

Omor,

can you try code like this (based on MFC/2. COM Object With Events sample), change void CWithEventsView::OnInitialUpdate() sample:
[code]if (!m_Ftp.CreateDispatch( WeOnlyDo.wodFtpDLXCom.1 ,NULL))
{
AfxMessageBox( Could not create wodFtpDLX object ,MB_OK,0);
return;
}
if (!m_Cert.CreateDispatch( WeOnlyDo.Certificate.1 ,NULL))
{
AfxMessageBox( Could not create Certificate object ,MB_OK,0);
return;
}

VARIANT var;
var.vt = VT_ERROR;
m_Cert.LoadKey( ... , var);
m_Cert.Load( ... , var);

// let's initialize FtpX events
m_FtpEvents = new CEventSink;;
LPUNKNOWN pUnknown= m_FtpEvents->GetIDispatch(FALSE);
AfxConnectionAdvise(m_Ftp.m_lpDispatch,DIID__IwodFtpDLXComEvents,pUnknown,FALSE,&m_Cookie);

// great, we have everything. Let's just inform events class about our existance :)
m_FtpEvents->m_pCtrl=this;


m_Ftp.SetHostname( your_hostname );
m_Ftp.SetLogin( your_login );
m_Ftp.SetPassword( not_needed );
m_Ftp.SetAuthentication(2); //authCertificate
m_Ftp.SetRefCertificate(m_Cert);[/code]

See how I set certificate and how I initialize? Can you try the same?

Regards,
Kreso

Re: C++(MFC) SFTP with PrivateKey

by OMOR, Monday, July 24, 2006, 07:57 (6698 days ago) @ wodSupport

Ahhh
The function is called SetRefCertificate().
Thanks a lot

/OMOR