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

by OMOR, (6862 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

locked

Re: C++(MFC) SFTP with PrivateKey

by Jasmine, (6862 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

locked

Re: C++(MFC) SFTP with PrivateKey

by OMOR, (6861 days ago) @ Jasmine

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?

locked

Re: C++(MFC) SFTP with PrivateKey

by wodDamir @, (6861 days ago) @ OMOR

Hi OMOR,

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

Regards,
Damir

locked

Re: C++(MFC) SFTP with PrivateKey

by OMOR, (6861 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?

locked

Re: C++(MFC) SFTP with PrivateKey

by Jasmine, (6861 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

locked

Re: C++(MFC) SFTP with PrivateKey

by OMOR, (6858 days ago) @ Jasmine

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

/OMOR

locked