diff --git a/SMBLibrary/Client/SMB1Client.cs b/SMBLibrary/Client/SMB1Client.cs index 9ebf50d..3ad47d4 100644 --- a/SMBLibrary/Client/SMB1Client.cs +++ b/SMBLibrary/Client/SMB1Client.cs @@ -688,14 +688,14 @@ namespace SMBLibrary.Client } } - public static void TrySendMessage(Socket socket, SMB1Message message) + private void TrySendMessage(Socket socket, SMB1Message message) { SessionMessagePacket packet = new SessionMessagePacket(); packet.Trailer = message.GetBytes(); TrySendPacket(socket, packet); } - public static void TrySendPacket(Socket socket, SessionPacket packet) + private void TrySendPacket(Socket socket, SessionPacket packet) { try { @@ -704,9 +704,11 @@ namespace SMBLibrary.Client } catch (SocketException) { + m_isConnected = false; } catch (ObjectDisposedException) { + m_isConnected = false; } } } diff --git a/SMBLibrary/Client/SMB1FileStore.cs b/SMBLibrary/Client/SMB1FileStore.cs index c0a4130..6ac04ab 100644 --- a/SMBLibrary/Client/SMB1FileStore.cs +++ b/SMBLibrary/Client/SMB1FileStore.cs @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2019 Tal Aloni . All rights reserved. +/* Copyright (C) 2014-2023 Tal Aloni . All rights reserved. * * You can redistribute this program and/or modify it under the terms of * the GNU Lesser Public License as published by the Free Software Foundation, @@ -560,6 +560,10 @@ namespace SMBLibrary.Client private void TrySendMessage(SMB1Command request) { + if (!m_client.IsConnected) + { + throw new InvalidOperationException("The client is no longer connected"); + } m_client.TrySendMessage(request, m_treeID); } diff --git a/SMBLibrary/Client/SMB2Client.cs b/SMBLibrary/Client/SMB2Client.cs index 4ef93a8..eb14750 100644 --- a/SMBLibrary/Client/SMB2Client.cs +++ b/SMBLibrary/Client/SMB2Client.cs @@ -640,7 +640,7 @@ namespace SMBLibrary.Client } } - public static void TrySendCommand(Socket socket, SMB2Command request, byte[] encryptionKey) + private void TrySendCommand(Socket socket, SMB2Command request, byte[] encryptionKey) { SessionMessagePacket packet = new SessionMessagePacket(); if (encryptionKey != null) @@ -655,7 +655,7 @@ namespace SMBLibrary.Client TrySendPacket(socket, packet); } - public static void TrySendPacket(Socket socket, SessionPacket packet) + private void TrySendPacket(Socket socket, SessionPacket packet) { try { @@ -664,9 +664,11 @@ namespace SMBLibrary.Client } catch (SocketException) { + m_isConnected = false; } catch (ObjectDisposedException) { + m_isConnected = false; } } } diff --git a/SMBLibrary/Client/SMB2FileStore.cs b/SMBLibrary/Client/SMB2FileStore.cs index 64607d7..563514c 100644 --- a/SMBLibrary/Client/SMB2FileStore.cs +++ b/SMBLibrary/Client/SMB2FileStore.cs @@ -1,4 +1,4 @@ -/* Copyright (C) 2017-2021 Tal Aloni . All rights reserved. +/* Copyright (C) 2017-2023 Tal Aloni . All rights reserved. * * You can redistribute this program and/or modify it under the terms of * the GNU Lesser Public License as published by the Free Software Foundation, @@ -335,6 +335,10 @@ namespace SMBLibrary.Client private void TrySendCommand(SMB2Command request) { request.Header.TreeID = m_treeID; + if (!m_client.IsConnected) + { + throw new InvalidOperationException("The client is no longer connected"); + } m_client.TrySendCommand(request, m_encryptShareData); }