sshnet / SSH.NET

SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism.
http://sshnet.github.io/SSH.NET/
MIT License
4k stars 931 forks source link

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

Open avisosoft opened 2 years ago

avisosoft commented 2 years ago

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 commented 2 years ago

have found workaround by running quick DownloadFile right before UploadFile

IgorMilavec commented 2 years ago

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 commented 2 years ago

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

Lamester commented 2 weeks ago

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

revealer409 commented 1 day ago

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'