Callback issue in the FTP get function of 9160

How to determine if the download is complete when downloading files from the FTP server using the ftp_get function?

Although Ctrl_cb will return code, in my actual testing, when downloading a large file, the download was not completed yet, and Ctrl_cb already returned 226 code indicating that the transfer was completed. However, there was no callback message when the download was actually completed.

I haven't tested the ftp put function yet, may there be similar issues as well?

Parents Reply Children
  • Hi dejans,

    I tested FTP using SLM, which includes FTP_client h, and there are no other special settings for FTP. Then, as in the previous reply, I wrote two callback functions. In the ctrl callback, I only printed out the received information. In the data callback, I added some logical code to display the downloaded data volume and save the received data to LFS.

    Then below is the log I obtained, and I have removed some duplicate parts for easy viewing

    [10:37:57.976]收←◆ctrl_cb: 220 (vsFTPd 3.0.3)
    
    
    [10:37:58.250]收←◆ctrl_cb: 200 Always in UTF8 mode.
    
    
    [10:37:58.619]收←◆ctrl_cb: 331 Please specify the password.
    
    
    [10:37:59.136]收←◆ctrl_cb: 230 Login successful.
    
    lfs_dir_fetchmatch count: 4
    return 0 
    
    [10:37:59.416]收←◆ctrl_cb: 227 Entering Passive Mode (8,222,179,2,154,94)
    
    
    [10:38:02.131]收←◆data len = 708
    lfs_dir_fetchmatch count: 5
    return 0 
    
    [10:38:02.243]收←◆count: 1
    data len = 708
    
    [10:38:02.361]收←◆count: 2
    data len = 708
    
    [10:38:02.493]收←◆count: 3
    data len = 708
    
    [10:38:02.638]收←◆count: 4
    data len = 708
    
    [10:38:02.798]收←◆count: 5
    
    [10:38:04.418]收←◆data len = 708
    
    [10:38:04.685]收←◆count: 6
    data len = 708
    
    [10:38:04.793]收←◆count: 7
    data len = 708
    
    [10:38:04.918]收←◆count: 8
    data len = 708
    
    [10:38:05.017]收←◆ctrl_cb: 150 Opening BINARY mode data connection for /newdir/test2.bin (312643 bytes).
    
    
    [10:38:05.068]收←◆count: 9
    
    [10:38:06.165]收←◆data len = 708
    
    [10:38:06.313]收←◆count: 10
    
    [10:38:06.497]收←◆data len = 708
    
    [10:38:06.659]收←◆count: 11
    
    [10:38:06.784]收←◆data len = 632
    
    [10:38:07.059]收←◆count: 12
    data len = 708
    
    [10:38:07.180]收←◆count: 13
    
    [10:38:07.521]收←◆data len = 708
    
    [10:38:07.648]收←◆count: 14
    data len = 76
    
    [10:38:07.775]收←◆count: 15
    
    [10:38:08.642]收←◆data len = 708
    
                    Omit the same part in the middle here
    
    [10:39:04.092]收←◆count: 135
    
    [10:39:04.485]收←◆data len = 708
    
    [10:39:04.605]收←◆count: 136
    
    [10:39:05.040]收←◆ftp_get return = -116
    **********************************************mx_startTftp finish
    
    Upgrade OK
    OK
    
    [10:39:05.108]收←◆data len = 708
    FAIL: seek /lfs/test.bin: -9FAIL: write /lfs/test.bin: -9count: 137
    
    [10:39:05.634]收←◆data len = 708
    FAIL: seek /lfs/test.bin: -9FAIL: write /lfs/test.bin: -9count: 138
    
    [10:39:05.955]收←◆data len = 708
    FAIL: seek /lfs/test.bin: -9FAIL: write /lfs/test.bin: -9count: 139
    
    [10:39:06.274]收←◆data len = 708
    FAIL: seek /lfs/test.bin: -9FAIL: write /lfs/test.bin: -9count: 140
    
    [10:39:06.564]收←◆data len = 708
    FAIL: seek /lfs/test.bin: -9FAIL: write /lfs/test.bin: -9count: 141
    
    [10:39:06.998]收←◆data len = 708
    FAIL: seek /lfs/test.bin: -9FAIL: write /lfs/test.bin: -9count: 142
    
                   Omit the same part in the middle here
    
    [10:41:25.213]收←◆data len = 708
    FAIL: seek /lfs/test.bin: -9FAIL: write /lfs/test.bin: -9count: 441
    
    [10:41:25.500]收←◆data len = 708
    FAIL: seek /lfs/test.bin: -9FAIL: write /lfs/test.bin: -9count: 442
    
    [10:41:25.869]收←◆data len = 415
    FAIL: seek /lfs/test.bin: -9FAIL: write /lfs/test.bin: -9count: 443
    

    In the FTP data callback, I saved the downloaded data to LFS, but as you can see, when I downloaded about one-third of the time, it gave me a notification that the download was completed (usually returning a 226 code, this time it didn't return, but this is not important, except for not displaying the 226 code, everything else is exactly the same), and then the LFS file closed, causing me to be unable to write data. And when the download is actually completed in the end, there is no return code or any information

  • Hi,

    Documentation for SLM sample specifies that client behavior may vary depending on the server that is used for testing. Which FTP server did you use?

    You could try to test FTP connection using FTP AT commands.

    llly said:
    when I downloaded about one-third of the time, it gave me a notification that the download was completed

    Where is this shown in the log?

    Best regards,
    Dejan

  • Hi dejans

    I am using our own FTP server.

    The current log does not display 226, only a -116 connection timeout code. When downloading a relatively small file, the 226 code can be returned normally when the download is completed, but when downloading a large file, I think it should be because the download time exceeded the timeout time, so he thought the command timed out, which ultimately led to a return of -116?

    In other words, when downloading a large file, after a period of time (about one or two minutes?), if the download is not completed yet, ftp_get will return a -116 timeout code. How can we make it return 226 only when the download is completed, instead of -116?

  • Hi,

    In the FTP client library, there is CONFIG_FTP_CLIENT_KEEPALIVE_TIME option which is by default set to 60 seconds. You could try either to increase this value or turn the KEEPALIVE option off by changing its value to 0.

    Best regards,
    Dejan

  • Hi dejans

    I tested CONFIG_FTP_CLIENT_KEEPALIVE_TIME, but it didn't work. Instead, I modified FTP_DATA_TIMEOUT_SEC in ftp_client. c to solve this problem. It may not be the best solution, but currently it's not a big problem. Simply put, the time for ftp_get cannot exceed FTP_DATA_TIMEOUT_SEC, otherwise it will return -116, with a default of 60 seconds. Therefore, I will change this value to a few minutes. Perhaps you can improve this place a bit? But for me, this problem has been solved.

    Anyway, thank you for your help.

Related