If I run it from a Windows service, it hangs.

Advertisement

ToniJ
Guest

If I run it from a Windows service, it hangs.

Hi everybody,

My little application in VB6 uses successfully WinSCPnet.dll for connect to SFTP.
But if I use it from a Windows service, it freezes when trying to connect.
Could you help me,

Thanks and congratulations.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,442
Location:
Prague, Czechia

Re: If I run it from a Windows service, it hangs.

How did register the assembly for all users?

Please set Session.SessionLogPath and Session.DebugLogPath and post the logs.

Reply with quote

ToniJ
Guest

Here is how I register it.

C:\windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe "C:\NTV\DLL\WinSCPnet.dll" /codebase /tlb
and the winscp.exe is in C:\NTV\DLL, too.
Version: 5.18.3.0 => WinSCP 5.18 RC downloaded 4 May 2021

Thanks in advance.

Reply with quote

martin
Site Admin
martin avatar

Re: Here is how I register it.

Don't you get blocked somehow? I see in the log, that first time, the connection succeeds. But the second connection one second later hangs. Maybe the server does not like this. Why are you doing the fingerprint scan? Are you implementing a host key cache?

Reply with quote

Advertisement

ToniJ
Guest

If I run it from a windows service, it hangs.

First of all, thanks for your reply.

I assign the property mySessionOptions.SshHostKeyFingerprint because if I don't, we get error:
SessionOptions.Protocol is Protocol.Sftp or Protocol.Scp, but SessionOptions.SshHostKeyFingerprint is not set.
So, since I am going to connect with different Servers, what I do is request it with mySession.ScanFingerprint(mySessionOptions, "SHA-256") and assign mySessionOptions.SshHostKeyFingerprint before executing mySession.Open mySessionOptions.

From your words, I understand that we can connect without the need for set SshHostKeyFingerprint, but then how?

Thanks a lot.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,442
Location:
Prague, Czechia

Re: If I run it from a windows service, it hangs.

If you are calling the Session.ScanFingerprint for each and every connection, you are only ineffectively doing the same what you can achieve by setting SessionOptions.GiveUpSecurityAndAcceptAnySshHostKey
https://winscp.net/eng/docs/library_sessionoptions#giveupsecurityandacceptanysshhostkey
What is a security flaw.
Instead, the host key should be part of your session settings for each of your servers, along with the hostname and credentials.
See also https://winscp.net/eng/docs/faq_hostkey
For an alternative approach, see https://winscp.net/eng/docs/library_example_known_hosts
Or use the WinsCP 5.18 with its SshHostKeyPolicy.AcceptNew.

Reply with quote

ToniJ
Guest

If I run it from a windows service, it hangs.

Thanks Martin,

I have made the test of assigning the SshHostKeyFingerprint with the rest of credentials (without scan it).
To check, executing normally, it works.
But from Windows Service, it also hangs at the same point.

I don't have any antivirus or firewall that can block the connection.

I have tested on another computer, the same thing happens.

Any ideas?
Thanks

Reply with quote

ToniJ
Guest

If I run it from a windows service, it hangs.

I attach logs of other computer.
Assigning the SshHostKeyFingerprint with the rest of credentials (without scan it).

Thanks Martin
  • WinSCP[DebugLogPath][Servicio].log (25.77 KB, Private file)
  • WinSCP[SessionLogPath][Servicio].log (5.55 KB, Private file)

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,442
Location:
Prague, Czechia

Re: If I run it from a windows service, it hangs.

Can you post log file when "executing normally"?

Does the service have a network connectivity?
(btw, your previous logs used a different local account and different IPs, so it's difficult to compare them)

Reply with quote

ToniJ
Guest

Re: If I run it from a windows service, it hangs.

Hi, first of all, I apologize for the delay in responding and now I return to this topic, without leaving it. (In this case is SFTP type)
I attach sesison log and debug log, with versions of the execution from the user and also from the service.

I use WinSCP 5.19.6 (.NET assembly - COM Library)

As you can see, when running from the service, it doesn't connect. It hangs.
Instead, from the normal execution from the windows user, it does connect (but then the "Session is already opened" error appears when calling Session.ListDirectory, but that's another topic)

Note: AVAST Antivirus is stopped.
Note: I'm using Local System account in service. But if I use administrator user, the result is the same. It hangs.

Thanks for advance.
Toni.
  • Debug and SessionLogPath_Service.rar (4.1 KB, Private file)
Description: debug and session log execution in windows service
  • SessionLogPath_User.log (28.94 KB, Private file)
Description: session log normal execution
  • DebugLogPath_User.log (76.9 KB, Private file)
Description: debug log normal execution

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,442
Location:
Prague, Czechia

Re: If I run it from a windows service, it hangs.

The hostname resolves to different IPs in your two scenarios:
. 2022-03-07 10:22:57.234 Looking up host "sftp.commerce-connector.com" for SSH connection
. 2022-03-07 10:22:57.265 Connecting to 52.29.213.126 port 22
. 2022-03-07 12:20:22.640 Looking up host "sftp.commerce-connector.com" for SSH connection
. 2022-03-07 12:20:22.671 Connecting to 3.127.84.184 port 22
Please talk to your network administrator.

Reply with quote

Advertisement

ToniJ
Guest

Re: If I run it from a windows service, it hangs.

The explanation is that this DNS has several IPs (by mistake, I imagine) and each time, it resolves it randomly:
C:\Windows\System32>nslookup sftp.commerce-connector.com
Servidor:  250.red-80-58-61.staticip.rima-tde.net
Address:  80.58.61.250

Respuesta no autoritativa:
Nombre:  sftp.commerce-connector.com
Addresses:  3.127.84.184
          3.126.178.237
          52.29.213.126
Anyway, if we force connect to an IP, it always hangs on the Authenticating point from Windows Service.
I think it is the same problem as the other post (in that case, it's FTP), that when we are running from Windows Service, it hangs.
I have attached updated logs with a level of detail 2.

I think we are close to solving it. ;)

Thanks a lot Martin !!!
  • From Service (HANGS).zip (4.12 KB, Private file)
  • From User (WORKS).zip (9.68 KB, Private file)

Reply with quote

martin
Site Admin
martin avatar

Re: If I run it from a windows service, it hangs.

Thanks for posting your findings. I'm not sure if you expect anything from us now :)

Reply with quote

ToniJ
Guest

Re: If I run it from a windows service, it hangs.

Yes, Martin, I mean that for some reason, when trying to open the FTP/SFTP from the Windows service, it hangs (in both posts)

This is a good clue for you to find out the cause and to solve it.

I wait for news. Thanks, Martin.

Reply with quote

Advertisement

ToniJ
Guest

Re: If I run it from a windows service, it hangs.

Wait Martin, I have found a possible cause on my part, related to the open files to debug the main program.

It seems that after calling the open of the winscpnet.dll, it affects the open files of my main program, since they will not be left with the same state.
If I disable my log file, everything works fine from the windows service.

Reply with quote

ToniJ
Guest

Re: If I run it from a windows service, it hangs.

Confirmed Martin, if I close my application's log file before calling your Open method and then open the log file again, everything works fine.
For your information, I have this log file open with the LOCK APPEND property, in case it helps you in the future.
Thank you very much for your help Martin, it has been very helpful.

Reply with quote

Advertisement

You can post new topics in this forum