SSH.NET icon indicating copy to clipboard operation
SSH.NET copied to clipboard

SftpClient UploadFile throws SocketException: 'An existing connection was forcibly closed by the remote host'

Open avisosoft opened this issue 3 years ago • 5 comments

This exception has been thrown when VPN client is connected. Same code works fine if VPN is switch off.

image

StackTrace:

at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at Renci.SshNet.Abstractions.SocketAbstraction.Send(Socket socket, Byte[] data, Int32 offset, Int32 size) at Renci.SshNet.Session.SendPacket(Byte[] packet, Int32 offset, Int32 length) at Renci.SshNet.Session.SendMessage(Message message) at Renci.SshNet.Session.Renci.SshNet.ISession.SendMessage(Message message) at Renci.SshNet.Channels.Channel.SendData(Byte[] data, Int32 offset, Int32 size) at Renci.SshNet.Channels.Channel.SendData(Byte[] data) at Renci.SshNet.SubsystemSession.SendData(Byte[] data) at Renci.SshNet.Sftp.SftpSession.SendRequest(SftpRequest request) at Renci.SshNet.Sftp.SftpSession.RequestWrite(Byte[] handle, UInt64 serverOffset, Byte[] data, Int32 offset, Int32 length, AutoResetEvent wait, Action1 writeCompleted) at Renci.SshNet.SftpClient.InternalUploadFile(Stream input, String path, Flags flags, SftpUploadAsyncResult asyncResult, Action1 uploadCallback) at Renci.SshNet.SftpClient.UploadFile(Stream input, String path, Boolean canOverride, Action`1 uploadCallback)

avisosoft avatar Apr 09 '22 15:04 avisosoft

have found workaround by running quick DownloadFile right before UploadFile

avisosoft avatar Apr 11 '22 13:04 avisosoft

Hm, this workaround is a bit too woodoo for my taste. I've never had a problem with UploadFile(), but I've never used ChangeDirectory() and instead used absolute path in UploadFile(). Can you try that and see how it works for you?

IgorMilavec avatar Apr 23 '22 11:04 IgorMilavec

Just noticed the VPN part in your post... then it all depends on the VPN implementation and configuration I guess...

IgorMilavec avatar Apr 23 '22 11:04 IgorMilavec

I'm running into this same issue. Is there a fix?

Lamester avatar Oct 23 '24 19:10 Lamester

Solution: In my case I was using SSH.NET library from some xyz vendor removed package from Nugget package manager and then installed SSH.NET by Renci fixed my issue.

issue background: due to some issue infra team has deleted FTP/*/Log directory from Server after that i was getting this issue 'An existing connection was forcibly closed by the remote host'

revealer409 avatar Nov 07 '24 05:11 revealer409