Skip to content

Timed out trying to read data from the socket stream! #122

Closed

Description

@JWcodeDev

NOTE FROM ADMIN:

This should be fixed in 29.0.0 and onwards.
But if you still have this issue, please add your post below instead of creating duplicate issues!

Thanks.


I am not able to upload a file to a FTPS site. I keep receiving the following error. If the file exists it will delete the file from the FTP but it will not upload the new file.

{"Timed out trying to read data from the socket stream!"}

Here is my code:

        FtpClient client = new FtpClient("ftp", "user", "pwd");

        client.DataConnectionType = FtpDataConnectionType.PASV;
        client.EncryptionMode = FtpEncryptionMode.Explicit;
        client.SslProtocols = System.Security.Authentication.SslProtocols.Tls11;
        client.ValidateCertificate += new FtpSslValidation(OnValidateCertificate);
        client.Encoding = System.Text.Encoding.ASCII;

        client.UploadFile(@"C:\Test\Test.txt", "/archive/Test.txt", FtpExists.Overwrite, true, FtpVerify.Retry);

         client.Disconnect();

It errors out on the client.UploadFile line.

Seems it is in the GetRequestStream(). Not sure how to over come this error.

Thanks,

JW

Activity

  1. robinrodricks commented on Jun 15, 2017

    @robinrodricks
    Owner

    Please send full logs in order for us to debug. Read the FAQ on how to print or save logs to a file.

  2. JWcodeDev commented on Jun 15, 2017

    @JWcodeDev
    Author

    Thanks for the Response.

    Here are the logs:

    # UploadFile("C:\Test\Test.txt", "/Test.txt", Overwrite, True, None)
    
    # FileExists("/Test.txt")
    
    # Connect()
    Status:   Connecting to ***:21
    Response: 220 Welcome To  Solutions.  All traffic is monitored and scanned.
    Response: 220-Microsoft FTP Service
    Command:  AUTH TLS
    Response: 234 AUTH command ok. Expecting TLS Negotiation.
    Status:   FTPS Authentication Successful
    Status:   Time to activate encryption: 0h 0m 0s.  Total Seconds: 0.3145793.
    Command:  USER ***
    Response: 331 Password required
    Command:  PASSS ***
    Response: 230 User logged in.
    Command:  PBSZ 0
    Response: 200 PBSZ command successful.
    Command:  PROT P
    Response: 200 PROT command successful.
    Command:  FEAT
    Response: 211 END
    Response: 211-Extended features supported:
    Response: LANG EN*
    Response: UTF8
    Response: AUTH TLS;TLS-C;SSL;TLS-P;
    Response: PBSZ
    Response: PROT C;P;
    Response: CCC
    Response: HOST
    Response: SIZE
    Response: MDTM
    Response: REST STREAM
    Status:   Text encoding: System.Text.ASCIIEncoding
    Command:  SYST
    Response: 215 Windows_NT
    Status:   Auto-detected Windows listing parser
    Command:  SIZE /Test.txt
    Response: 550 The system cannot find the file specified. 
    
    # DirectoryExists("")
    
    # OpenWrite("/Test.txt", Binary)
    Command:  TYPE I
    Response: 200 Type set to I.
    
    # GetFileSize("/Test.txt")
    Command:  SIZE /Test.txt
    Response: 550 The system cannot find the file specified. 
    
    # OpenPassiveDataStream(PASV, "STOR /Test.txt", 0)
    Command:  PASV
    Response: 227 Entering Passive Mode (00,00,00,00,153,114).
    Status:   Connecting to ***:39282
    Command:  STOR /Test.txt
    
    UnhandledExceptionHandler - Error while uploading the file to the server. See InnerException for more info..
       at FluentFTP.FtpClient.UploadFileInternal(Stream fileData, String remotePath, Boolean createRemoteDir, FtpExists existsMode, Boolean fileExists, Boolean fileExistsKnown)
       at FluentFTP.FtpClient.UploadFileFromFile(String localPath, String remotePath, Boolean createRemoteDir, FtpExists existsMode, Boolean fileExists, Boolean fileExistsKnown, FtpVerify verifyOptions)
       at FluentFTP.FtpClient.UploadFile(String localPath, String remotePath, FtpExists existsMode, Boolean createRemoteDir, FtpVerify verifyOptions)
       at FTP2.Program.Main(String[] args) in c:\AAA_Projects\FTP2\FTP2\Program.cs:line 55
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
    
    Inner Exception:
    
    {"Timed out trying to read data from the socket stream!"}
    
  3. robinrodricks commented on Jun 15, 2017

    @robinrodricks
    Owner

    When you use FileZilla does it work? Can you do this to verify and also paste the FileZilla logs here so I can compare what it does different?

  4. JWcodeDev commented on Jun 15, 2017

    @JWcodeDev
    Author

    I actually can't get a directory listing through FileZilla but I can through other FTP Clients.

  5. robinrodricks commented on Jun 18, 2017

    @robinrodricks
    Owner

    Okay use another client but paste the FTP logs so we can compare with our library.

  6. JWcodeDev commented on Jun 19, 2017

    @JWcodeDev
    Author

    Here is the log from Core FTP with a successful file transfer.

    Resolving ***...  
    Connect socket #1488 to ***, port 21...
    220-Microsoft FTP Service  
    220-Microsoft FTP Service  
    220 Welcome To Solutions.  All traffic is monitored and scanned.  
    AUTH TLS  
    234 AUTH command ok. Expecting TLS Negotiation.  
    TLSv1.2, cipher TLSv1/SSLv3 (ECDHE-RSA-AES256-SHA384) - 256 bit
    USER ***  
    331 Password required  
    PASS **********  
    230 User logged in.  
    SYST  
    215 Windows_NT  
    Keep alive off...
    PWD  
    257 "/" is current directory.  
    PBSZ 0  
    200 PBSZ command successful.  
    PROT P  
    200 PROT command successful.  
    PASV  
    227 Entering Passive Mode (***,196,23).  
    LIST  
    Connect socket #1292 to ***, port 50199...
    150 Opening ASCII mode data connection.  
    TLSv1.2, cipher TLSv1/SSLv3 (ECDHE-RSA-AES256-SHA384) - 256 bit
    226 Transfer complete.  
    Transferred 48 bytes in 0.017 seconds  
    PWD  
    257 "/" is current directory.  
    TYPE A  
    200 Type set to A.  
    PASV  
    227 Entering Passive Mode (***,196,24).  
    STOR Leads_20170619.csv  
    Connect socket #1440 to ***, port 50200...
    TLSv1.2, cipher TLSv1/SSLv3 (ECDHE-RSA-AES256-SHA384) - 256 bit
    150 Opening ASCII mode data connection.  
    226 Transfer complete.  
    Leads_20170619.csv - 31967 bytes transferred in 0 seconds  
    MDTM 20170619124726 Leads_20170619.csv  
    213 20170619124726  
    Transfer time: 00:00:01  
    
  7. molekamp commented on Jun 20, 2017

    @molekamp

    This is very similar to my issue #124, not only because of the same error message ("Timed out trying to read data from the socket stream!") but also because of ASCII vs Binary mode. In your example of a successful transfer, the type is set to ASCII prior to the upload:

    TYPE A  
    200 Type set to A.  
    PASV  
    227 Entering Passive Mode (***,196,24).  
    STOR Leads_20170619.csv 
    

    In your logs of the failed transfer on the other hand, the data mode is set to Binary prior to the transfer:

    # OpenWrite("/Test.txt", Binary)
    Command:  TYPE I
    Response: 200 Type set to I.
    
    # GetFileSize("/Test.txt")
    Command:  SIZE /Test.txt
    Response: 550 The system cannot find the file specified. 
    
    # OpenPassiveDataStream(PASV, "STOR /Test.txt", 0)
    Command:  PASV
    Response: 227 Entering Passive Mode (00,00,00,00,153,114).
    Status:   Connecting to ***:39282
    Command:  STOR /Test.txt
    
    
  8. robinrodricks commented on Jun 21, 2017

    @robinrodricks
    Owner

    @molekamp Amazing that you two have a similar error and thanks for debugging this use case. I will try to support ASCII transfers for the high level APIs too.

  9. robinrodricks commented on Jun 22, 2017

    @robinrodricks
    Owner

    @JWcodeDev

    Can you try this beta version, which has new properties (UploadDataType, DownloadDataType) that control usage of the ASCII/Binary mode with the high level API.

    Specifically in your case set both to use ASCII mode and that should mimic the behavior by CoreFTP.

  10. Repository owner deleted a comment from gattamanenim on Aug 8, 2017
  11. greydmar commented on Jan 11, 2018

    @greydmar

    I had same issue here.
    With Winscp works normally.
    After some hours and retries i've found that change

    DataConnectionType = FtpDataConnectionType.EPSV,
    the problem vanishes ! :)

    The choice the connection type involves examinate some server response messages.
    In my case, Server response (Thanks FluentFTP Trace)

    Connect()

    Status: Connecting to ***********
    Response: 220 Bs As Argentina
    Response: 220-FileZilla Server 0.9.60 beta
    (sensible information)
    Response: 220-Si no cuenta con la autorizacion, por favor desconecte su sesion
    Response: 220-inmediatamente!
    Response: 220-
    Command: PASS ***
    Response: 230 Logged on
    Command: FEAT
    Response: 211 End
    Response: 211-Features:
    Response: MDTM
    Response: REST STREAM
    Response: SIZE
    Response: MLST type*;size*;modify*;
    Response: MLSD
    Response: AUTH SSL
    Response: AUTH TLS
    Response: PROT
    Response: PBSZ
    Response: UTF8
    Response: CLNT
    Response: MFMT
    Response: EPSV
    Response: EPRT

    Status: Text encoding: System.Text.ASCIIEncoding
    Command: SYST
    Response: 215 UNIX emulated by FileZilla
    Status: Auto-detected UNIX listing parser

  12. fschwengsbier commented on Jul 25, 2018

    @fschwengsbier

    Yeah.
    DataConnectionType = FtpDataConnectionType.EPSV did the trick.
    Now I'm able to upload large files.

    The C# intellisense recommends this setting. So why we have to set it?

  13. changed the title [-]Unable to Upload File to FTP[/-] [+]Unable to Upload File to FTP - Timed out trying to read data from the socket stream![/+] on Jan 31, 2019
  14. robinrodricks commented on Jan 31, 2019

    @robinrodricks
    Owner

    @fschwengsbier Not sure why intellisense recommends it. By design of the original author, the library first tries EPSV then passive then gives up. Not sure why its not working in your case.

  15. 18 remaining items

  16. fayezm commented on Aug 19, 2020

    @fayezm

    Just a follow up on this - we were using .net core v2 when this issue was occurring, hosted on both Linux and Windows. As an act of desperation, we re-wrote our application targeting .NET Framework 4.7 and this issue does not occur at all.

  17. Hidend commented on Nov 16, 2020

    @Hidend

    I do have this error seems like when doing GetListing() using net core v3

    Status: Disposing FtpSocketStream...
    Warning: FtpClient.Disconnect(): Exception caught and discarded while closing control connection: System.TimeoutException: Timed out trying to read data from the socket stream!
    at FluentFTP.FtpSocketStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken token)
    at FluentFTP.FtpSocketStream.ReadLineAsync(Encoding encoding, CancellationToken token)
    at FluentFTP.FtpClient.GetReplyAsync(CancellationToken token)
    at FluentFTP.FtpClient.ExecuteAsync(String command, CancellationToken token)
    at FluentFTP.FtpClient.DisconnectAsync(CancellationToken token)
    Status: Disposing FtpSocketStream...

  18. VictorKrs commented on Feb 9, 2021

    @VictorKrs

    Hi,
    I have this exception when trying read file from ftp server and file starts with "220" and has few strings.
    For example, text in file:

    220someText
    someText2
    

    Code:

    static void Main(string[] args)
    {
        RunFTP();
    }
    static void RunFTP()
    {
        string hostname = "192.168.1.229";
        int port = 21;
        string username = "FTP_User";
        string password = "123";
        string fileName = @"Test/Test220.txt";
    
        FtpClient client = new FtpClient(hostname, port, username, password);
        List<FtpProfile> profile = client.AutoDetect();
        client.LoadProfile(profile[0]);
        client.Connect();
    
        string[] data = GetDataFromFile(fileName, client);
    
        Console.ReadKey();
    }

    Tried this way:

    private static string[] GetDataFromFile(string _fileName, FtpClient _client)
    {
        try
        {
            return ReadLines(() => _client.OpenRead(_fileName), encoding).ToArray();
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
            return null;
        }
    }
    private static IEnumerable<string> ReadLines(Func<Stream> _streamProvider, Encoding _encoding)
    {
        using (var stream = _streamProvider())
        using (var reader = new StreamReader(stream, _encoding))
        {
            string line;
    
            while ((line = reader.ReadLine()) != null)
                yield return line;
        }
    }

    And this:

    private static string[] GetDataFromFile(string _fileName, FtpClient _client)
    {
        try
        {
            using (MemoryStream stream = new MemoryStream())
            {
                bool status = _client.Download(stream, _fileName);
                stream.Position = 0;
                List<string> data = new List<string>();
                using (var reader = new StreamReader(stream, encoding))
                {
                    string line;
    
                    while ((line = reader.ReadLine()) != null)
                        data.Add(line);
                }
                return data.ToArray();
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
            return null;
        }
    }

    Both ways works when file data don't start on "220".
    If start, first string reads and then when trying to read next string throw exception: "Timed out trying to read data from the socket stream"

    .Net framework 4.0
    FluentFtp version: 33.0.3

  19. unpinned this issue on Aug 5, 2022
  20. parthvnp commented on Feb 23, 2023

    @parthvnp

    Does this issue still need help? Happy to work on it.

  21. FanDjango commented on Feb 24, 2023

    @FanDjango
    Collaborator

    Closing. Please open separate new issues if you encounter problems.

  22. Repository owner deleted a comment from crocket01 on Nov 16, 2023
  23. Repository owner deleted a comment from kuyz123 on Nov 16, 2023
  24. robinrodricks commented on Nov 16, 2023

    @robinrodricks
    Owner

    PLEASE OPEN NEW ISSUES IF YOU ENCOUNTER THIS ISSUE.

    DO NOT ADD YOUR COMMENT HERE.

    WE WILL NOT DEBUG OLDER VERSIONS OF FLUENT FTP. SO ENSURE YOU ARE USING THE LATEST VERSION.

  25. Repository owner locked as spam and limited conversation to collaborators on Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址