2 instances of wodFTPDCom possible? - WeOnlyDo Discussion board

2 instances of wodFTPDCom possible? (wodFTPServer)

by Hugo, Monday, August 10, 2020, 15:02 (1576 days ago) @ Jasmine

Will try to give as much info as I can!

I have a c# exe which, at startup, creates a SFTP opr FTP server using the wodFTPDCom component.
Here is the code that does that:

1. During the init, there is a call:
this.permanentServerSftpFtp = this.TryStartFtp(this.sftpFtpstring, this.settings.FtpPortSftp, out result)
2. (stripped) code TryStartFtp

private wodFTPDCom TryStartFtp(string sftpFtpstring, int port, out MethodResult result)
{
try
{
// Instantiate, configure and start a WeOnlyDo component for FTP hosting
wodFTPDCom sftpFtpServer = new wodFTPDCom();
sftpFtpServer.LicenseKey = FtpServer.WodLicenseKey;

if (SFTP)
{
// Generate the needed key pair
Interop.WODSSHKeyLib.Keys key = new KeysClass();
key.Generate(Interop.WODSSHKeyLib.SSHKeyTypes.RSAkey, 1024);
sftpFtpServer.Certificate = key;
sftpFtpServer.Protocol = ProtocolsEnum.SFTP;
sftpFtpServer.Authentication = AuthenticationsEnum.authPassword;
}
else
{
sftpFtpServer.Protocol = ProtocolsEnum.FTP;
}

sftpFtpServer.Threads = false;
sftpFtpServer.PasvPort = 20;
this.HookupEvents(sftpFtpServer);
sftpFtpServer.Start(port);
return sftpFtpServer;
}
catch (Exception ex)
{
return null;
}
}
3. This all goes well and after startup, I can connect with a client and fe. download files for both FTP and SFTP mode

4. Now, when the app is started in SFTP mode (SFTP server is running), there is this itf call that executes (stripped code), this calls basically the same start procedure TryStartFtp

public override void StartTemporaryFtpServer(out MethodResult result)
{
try
{
this.temporaryServerFtp = this.TryStartFtp("FTP", this.settings.FtpPortFtp, out result);
}
catch (Exception e)
{
}
}

5. If this itf is called, the exception is thrown on the line 'sftpFtpServer.LicenseKey = FtpServer.WodLicenseKey'
basically the first itf call that is executed on the newly created wodFTPDCom component.

=>

System.InvalidCastException: Unable to cast COM object of type 'Interop.wodFTPDComLib.wodFTPDComClass' to interface type 'Interop.wodFTPDComLib.IwodFTPDCom'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{6DBFD532-B6F6-4986-A5F2-6D51EBC756B1}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget, Boolean& pfNeedsRelease)
at Interop.wodFTPDComLib.wodFTPDComClass.set_LicenseKey(String pVal)
at OMSE.FtpServer.FtpServer.TryStartFtp(String sftpFtpstring, Int32 port, MethodResult& result) in D:\GIT\TXCARE_DEVELOP1\Src\FtpServer\FtpServer.cs:line 503, parameters: System.InvalidCastException:

'


Complete thread: