{"action":"created","issue":{"url":"https://api.github.com/repos/robinrodricks/FluentFTP/issues/335","repository_url":"https://api.github.com/repos/robinrodricks/FluentFTP","labels_url":"https://api.github.com/repos/robinrodricks/FluentFTP/issues/335/labels{/name}","comments_url":"https://api.github.com/repos/robinrodricks/FluentFTP/issues/335/comments","events_url":"https://api.github.com/repos/robinrodricks/FluentFTP/issues/335/events","html_url":"https://github.com/robinrodricks/FluentFTP/issues/335","id":360281453,"node_id":"MDU6SXNzdWUzNjAyODE0NTM=","number":335,"title":"Problem with multiple instances - Authentication failed because the remote party has closed the transport stream","user":{"login":"sullivanets1","id":16138375,"node_id":"MDQ6VXNlcjE2MTM4Mzc1","avatar_url":"https://avatars3.githubusercontent.com/u/16138375?v=4","gravatar_id":"","url":"https://api.github.com/users/sullivanets1","html_url":"https://github.com/sullivanets1","followers_url":"https://api.github.com/users/sullivanets1/followers","following_url":"https://api.github.com/users/sullivanets1/following{/other_user}","gists_url":"https://api.github.com/users/sullivanets1/gists{/gist_id}","starred_url":"https://api.github.com/users/sullivanets1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sullivanets1/subscriptions","organizations_url":"https://api.github.com/users/sullivanets1/orgs","repos_url":"https://api.github.com/users/sullivanets1/repos","events_url":"https://api.github.com/users/sullivanets1/events{/privacy}","received_events_url":"https://api.github.com/users/sullivanets1/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-14T12:18:37Z","updated_at":"2018-09-17T12:36:57Z","closed_at":null,"author_association":"NONE","body":"**FTP OS:**  Windows \r\n\r\n**FTP Server:** filezilla\r\n\r\n**Computer OS:**  windows\r\n\r\n\r\nAny advice for how I can sort the below problem is appreciated.  I have code inside of an httphandler which I am using the serve files on a website. Basically this is used as a dynamic replacement instead of linking directly to a file. It takes an ID as input, checks database & permissions then responds back with the associated file. The file itself is stored off site on a different location. I have been instructed to use ftp to bring the file back to the our server. Our server environment is using .net 3.5.\r\n\r\nThe code I have is working without error when only a single ftp action is happening at one time.\r\n\r\nHowever when the httphandler is being called multiple times simultaneously (e.g. if 4 people are using it once or one person executes 4 times at once) then some of the executions fail, with exception noted below.\r\n\r\nGoing by the logs I'm guessing that additional instances are disposing of still active previous instances - can that be prevented?\r\n\r\nthe relevant piece of code for this is as follows\r\n\r\n```\r\n            // Prepare ftp details.\r\n            FluentFTP.FtpTrace.AddListener(new System.Diagnostics.TextWriterTraceListener(traceFileAddress));\r\n            FluentFTP.FtpClient client = new FluentFTP.FtpClient(hostAddress, ftpUSername, ftpPassword); \r\n            client.EncryptionMode = FluentFTP.FtpEncryptionMode.Implicit;  \r\n            client.SslProtocols = System.Security.Authentication.SslProtocols.Tls;\r\n            client.DataConnectionType = FluentFTP.FtpDataConnectionType.EPSV;\r\n            client.ValidateCertificate += new FluentFTP.FtpSslValidation(OnValidateCertificate);\r\n\r\n\r\n            try\r\n            {\r\n                //Actually connect to ftp server.\r\n                client.Connect();\r\n\r\n                client.RetryAttempts = 3;\r\n                client.DownloadFile(downloadByFtpDestination, downloadByFtpSource, true, FtpVerify.Retry | FtpVerify.Throw);\r\n\r\n                client.Disconnect();\r\n                result = true;\r\n            }\r\n            catch (Exception ex)\r\n            {\r\n                result = false;\r\n                SsFile.writeToLog(\"ftp download error\", ex.Message + ex.InnerException, procesIdentifier);\r\n            }\r\n```\r\n\r\n\r\n\r\n\r\nIn the below example in the logs, file 002.zip.zip was successfully downloaded, 001.rar.zip failed.\r\n\r\n.net exception\r\n```\r\nError while downloading the file from the server. See InnerException for more info.System.IO.IOException: Authentication failed because the remote party has closed the transport stream.\r\n   at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)\r\n   at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation)\r\n   at FluentFTP.FtpSocketStream.ActivateEncryption(String targethost, X509CertificateCollection clientCerts, SslProtocols sslProtocols)\r\n   at FluentFTP.FtpClient.OpenPassiveDataStream(FtpDataConnectionType type, String command, Int64 restart)\r\n   at FluentFTP.FtpClient.OpenDataStream(String command, Int64 restart)\r\n   at FluentFTP.FtpClient.OpenRead(String path, FtpDataType type, Int64 restart, Boolean checkIfFileExists)\r\n   at FluentFTP.FtpClient.DownloadFileInternal(String remotePath, Stream outStream, IProgress`1 progress)\r\n```\r\n\r\n\r\n\r\n\r\n\r\n\r\n**Logs :**\r\n\r\n\r\n```\r\n\r\n# Connect()\r\nStatus:   Connecting to **Debug-IP-Address*:990\r\n\r\n# Connect()\r\nStatus:   Connecting to **Debug-IP-Address*:990\r\nStatus:   FTPS Authentication Successful\r\nStatus:   Time to activate encryption: 0h 0m 0s.  Total Seconds: 0.1130339.\r\nResponse: 220 Please visit https://filezilla-project.org/\r\nResponse: 220-FileZilla Server 0.9.60 beta\r\nResponse: 220-written by Tim Kosse (tim.kosse@filezilla-project.org)\r\nCommand:  USER debugUser\r\nResponse: 331 Password required for debugUser\r\nCommand:  PASS ***\r\nResponse: 230 Logged on\r\nCommand:  PBSZ 0\r\nResponse: 200 PBSZ=0\r\nCommand:  PROT P\r\nResponse: 200 Protection level set to P\r\nCommand:  FEAT\r\nResponse: 211 End\r\nResponse: 211-Features:\r\nResponse: MDTM\r\nResponse: REST STREAM\r\nResponse: SIZE\r\nResponse: MLST type*;size*;modify*;\r\nResponse: MLSD\r\nResponse: AUTH SSL\r\nResponse: AUTH TLS\r\nResponse: PROT\r\nResponse: PBSZ\r\nResponse: UTF8\r\nResponse: CLNT\r\nResponse: MFMT\r\nResponse: EPSV\r\nResponse: EPRT\r\nStatus:   Text encoding: System.Text.UTF8Encoding\r\nCommand:  OPTS UTF8 ON\r\nResponse: 202 UTF8 mode is always enabled. No need to send this command.\r\nCommand:  SYST\r\nStatus:   FTPS Authentication Successful\r\nResponse: 215 UNIX emulated by FileZilla\r\nStatus:   Auto-detected UNIX listing parser\r\nStatus:   Time to activate encryption: 0h 0m 0s.  Total Seconds: 0.1160348.\r\n\r\n# DownloadFile(\"c:\\debug\\encrypted\\001.rar.zip\", \"/debug/001.rar.zip\", True, Retry, Throw)\r\nResponse: 220 Please visit https://filezilla-project.org/\r\nResponse: 220-FileZilla Server 0.9.60 beta\r\nResponse: 220-written by Tim Kosse (tim.kosse@filezilla-project.org)\r\nCommand:  USER debugUser\r\nResponse: 331 Password required for debugUser\r\nCommand:  PASS ***\r\n\r\nResponse: 230 Logged on\r\nCommand:  PBSZ 0\r\n# OpenRead(\"/debug/001.rar.zip\", Binary, 0)\r\nCommand:  TYPE I\r\nResponse: 200 PBSZ=0\r\nCommand:  PROT P\r\nResponse: 200 Type set to I\r\nResponse: 200 Protection level set to P\r\nCommand:  FEAT\r\n\r\n# OpenPassiveDataStream(EPSV, \"RETR /debug/001.rar.zip\", 0)\r\nCommand:  EPSV\r\nResponse: 211 End\r\nResponse: 211-Features:\r\nResponse: MDTM\r\nResponse: REST STREAM\r\nResponse: SIZE\r\nResponse: MLST type*;size*;modify*;\r\nResponse: MLSD\r\nResponse: AUTH SSL\r\nResponse: AUTH TLS\r\nResponse: PROT\r\nResponse: PBSZ\r\nResponse: UTF8\r\nResponse: CLNT\r\nResponse: MFMT\r\nResponse: EPSV\r\nResponse: EPRT\r\n\r\n# Dispose()\r\nStatus:   Disposing FtpClient object...\r\nStatus:   Testing connectivity using Socket.Poll()...\r\nStatus:   Text encoding: System.Text.UTF8Encoding\r\nCommand:  OPTS UTF8 ON\r\nResponse: 229 Entering Extended Passive Mode (|||50508|)\r\nResponse: 202 UTF8 mode is always enabled. No need to send this command.\r\nCommand:  SYST\r\nResponse: 215 UNIX emulated by FileZilla\r\nStatus:   Auto-detected UNIX listing parser\r\n\r\nStatus:   Connecting to **Debug-IP-Address*:50508\r\n# DownloadFile(\"c:\\debug\\encrypted\\002.zip.zip\", \"/debug/002.zip.zip\", True, Retry, Throw)\r\nCommand:  RETR /debug/001.rar.zip\r\n\r\n# OpenRead(\"/debug/002.zip.zip\", Binary, 0)\r\nCommand:  TYPE I\r\nResponse: 150 Opening data channel for file download from server of \"/debug/001.rar.zip\"\r\nResponse: 200 Type set to I\r\n\r\n# OpenPassiveDataStream(EPSV, \"RETR /debug/002.zip.zip\", 0)\r\nCommand:  EPSV\r\nResponse: 229 Entering Extended Passive Mode (|||50272|)\r\nStatus:   Connecting to **Debug-IP-Address*:50272\r\nCommand:  RETR /debug/002.zip.zip\r\nResponse: 150 Opening data channel for file download from server of \"/debug/002.zip.zip\"\r\nStatus:   FTPS Authentication Successful\r\nStatus:   Time to activate encryption: 0h 0m 0s.  Total Seconds: 0.0080024.\r\nCommand:  QUIT\r\nResponse: 221 Goodbye\r\nStatus:   Disposing FtpSocketStream...\r\nStatus:   Disposing FtpSocketStream...\r\nStatus:   Disposing FtpSocketStream...\r\nStatus:   Disposing FtpSocketStream...\r\nResponse: 226 Successfully transferred \"/debug/002.zip.zip\"\r\nFile Verification: PASS\r\nCommand:  QUIT\r\nResponse: 221 Goodbye\r\nStatus:   Disposing FtpSocketStream...\r\n\r\n# Dispose()\r\nStatus:   Disposing FtpClient object...\r\nStatus:   There is stale data on the socket, maybe our connection timed out or you did not call GetReply(). Re-connecting...\r\nStatus:   Disposing FtpSocketStream...\r\nStatus:   Not sending QUIT because the connection has already been closed.\r\nStatus:   Disposing FtpSocketStream...\r\nStatus:   Disposing FtpSocketStream...\r\n\r\n# Dispose()\r\nStatus:   Disposing FtpClient object...\r\nStatus:   Disposing FtpSocketStream...\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/robinrodricks/FluentFTP/issues/comments/421997489","html_url":"https://github.com/robinrodricks/FluentFTP/issues/335#issuecomment-421997489","issue_url":"https://api.github.com/repos/robinrodricks/FluentFTP/issues/335","id":421997489,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMTk5NzQ4OQ==","user":{"login":"grahamehorner","id":3924941,"node_id":"MDQ6VXNlcjM5MjQ5NDE=","avatar_url":"https://avatars1.githubusercontent.com/u/3924941?v=4","gravatar_id":"","url":"https://api.github.com/users/grahamehorner","html_url":"https://github.com/grahamehorner","followers_url":"https://api.github.com/users/grahamehorner/followers","following_url":"https://api.github.com/users/grahamehorner/following{/other_user}","gists_url":"https://api.github.com/users/grahamehorner/gists{/gist_id}","starred_url":"https://api.github.com/users/grahamehorner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grahamehorner/subscriptions","organizations_url":"https://api.github.com/users/grahamehorner/orgs","repos_url":"https://api.github.com/users/grahamehorner/repos","events_url":"https://api.github.com/users/grahamehorner/events{/privacy}","received_events_url":"https://api.github.com/users/grahamehorner/received_events","type":"User","site_admin":false},"created_at":"2018-09-17T12:36:57Z","updated_at":"2018-09-17T12:36:57Z","author_association":"NONE","body":"also seeing this on a regular basis"}}
{"actor":{"display_login":"grahamehorner"}}