AT command sequence to retrieve a file from (simple/insecure) ftp server ?

4 thoughts on “AT command sequence to retrieve a file from (simple/insecure) ftp server ?

  1. I’d like to get a file over FTP.  I’m referring to documents : “HE910V2 AT commands reference guide 80418ST10126A Rev.1 ? 2013-11-27” and “IP Easy User Guide 80000ST10028A Rev. 19 ? 2014-09-03”

    The firmware I’m using is stream_HE910_NAG-12.00.318.bin as eventually it will be the ‘C’ program invoking the AT command interpreter, but for now I’m just pasting into a serial console.

    The FTP server I’m using is FileZilla, and as its behind a NAT firewall – so using passive mode.  I’ve tested the server with a couple of clients and can list and retrieve files in Explicit mode over TLS, as well as plaintext / insecure, that I’m using here.

    What I’m seeing is that once I have a connection, listing files (AT#FTPLIST=”/”), or retrieving one, just has the AT command interpreter sit there. (ignores +++ or subsequent AT commands).

    Looking through the FTP server log, the server thinks it send the file, and indeed I can see the contents of the file being sent through the server’s network connection (using Wireshark), including ACKs back from the modem.

    Something obvious I’m missing?  

    Various logs follow.

    This is the serial console of the modem:

    #STN: 5,0008               (spam from the modem on power up)

    at+CGDCONT=1,”IP”,”i2gold”,”0.0.0.0″              (PDP context set up for USA AT&T’s default data apn, and IP connection, IP address via DHCP)
    OK

    +PACSP0
    at#SGACT=1,1                                              (PDP context activation – returning a valid IP address after a second or two)
    #SGACT: 166.130.49.132

    OK
    at#FTPTO=1000                                           (FTP timeout config – tried leaving it in or out)
    OK
    at#FTPCFG=100,1,0                                     (Mainly setting TLS security off )
    OK
    at#FTPOPEN=”rubtucson.ddns.net”,”pi”,”Wombles42!”,1            (Passive connection to my server via DDNS – although direct IP address doesn’t fair any better)
    OK
    at#FTPTYPE=0                                              (Well eventually I want to retrieve binary files, but I’ve tried both binary and ascii with the same lack of result)
    OK
    at#FTPFSIZE=”Wombles.txt”                        (Its a teeny tiny (19char) text file in the root “/” of the ftp server, so no directory change required)
    #FTPFSIZE: 19

    OK
    at#FRWL?                                                                (Getting a bit desperate here – opening up the firewall to the server’s IP address – no change if I do this or not)
    OK
    at#FRWL=1,”107.2.43.204″,”255.255.255.0″
    OK
    at#FRWL?
    #FRWL: “107.002.043.204”,”255.255.255.000″

    OK
    at#FTPGET=”Wombles.txt”                                      (And this just sits there …   no OK or ERROR returned)

    This is the relevant log section of the FTP server:

    (000027)3/30/2017 10:52:01 AM – (not logged in) (166.130.49.132)> Connected on port 21, sending welcome message…
    (000027)3/30/2017 10:52:01 AM – (not logged in) (166.130.49.132)> 220 Restricted FTP server – all activity logged
    (000027)3/30/2017 10:52:01 AM – (not logged in) (166.130.49.132)> USER pi
    (000027)3/30/2017 10:52:01 AM – (not logged in) (166.130.49.132)> 331 Password required for pi
    (000027)3/30/2017 10:52:01 AM – (not logged in) (166.130.49.132)> PASS Wombles42!
    (000027)3/30/2017 10:52:01 AM – pi (166.130.49.132)> 230 Logged on
    (000027)3/30/2017 10:52:16 AM – pi (166.130.49.132)> TYPE I
    (000027)3/30/2017 10:52:16 AM – pi (166.130.49.132)> 200 Type set to I
    (000027)3/30/2017 10:52:22 AM – pi (166.130.49.132)> SIZE Wombles.txt
    (000027)3/30/2017 10:52:22 AM – pi (166.130.49.132)> 213 19
    (000027)3/30/2017 10:54:10 AM – pi (166.130.49.132)> PASV
    (000027)3/30/2017 10:54:10 AM – pi (166.130.49.132)> 227 Entering Passive Mode (107,2,43,204,125,32)
    (000027)3/30/2017 10:54:10 AM – pi (166.130.49.132)> RETR Wombles.txt
    (000027)3/30/2017 10:54:10 AM – pi (166.130.49.132)> 150 Opening data channel for file download from server of “/Wombles.txt”
    (000027)3/30/2017 10:54:10 AM – pi (166.130.49.132)> 226 Successfully transferred “/Wombles.txt”
    (000027)3/30/2017 11:04:11 AM – pi (166.130.49.132)> 421 Connection timed out.
    (000027)3/30/2017 11:04:11 AM – pi (166.130.49.132)> disconnected.

    What Wireshark shows is in the attached screenshot

    1. Hi Andrew, maybe is the communication flowcontrol? If you are not using HW flowcontrol set AT&K0.

      1. Hi,

        Thankyou,

        Setting AT&K0 at the start of the console session did indeed have the data arrive when testing on the serial port (300k of it ! )

        Now I think I know what “The file is received on the serial port.” in the manual means –   The file isn’t saved, instead its contents are written to the port you sent the AT command on.

        I’m working on duplicating the AT command sequence using m2m_os_iat_send_at_command() calls, and once I get passed AT#FTPOPEN (which I don’t currently have returning), does that mean that the entire file contents will arrive in the callback M2M_onReceiveResultCmd() in one hit?

        So I need to break it up using  #FTPGETPKT / AT#FTPRECV and file write api calls, or is there a simpler method?

        Cheers.

         Andrew

        1. Hi,

          Thankyou,

          Setting AT&K0 at the start of the console session did indeed have the data arrive when testing on the serial port (300k of it ! )

          Now I think I know what “The file is received on the serial port.” in the manual means –   The file isn’t saved, instead its contents are written to the port you sent the AT command on.

          I’m working on duplicating the AT command sequence using m2m_os_iat_send_at_command() calls, and once I get passed AT#FTPOPEN (which I don’t currently have returning), does that mean that the entire file contents will arrive in the callback M2M_onReceiveResultCmd() in one hit?

          So I need to break it up using  #FTPGETPKT / AT#FTPRECV and file write api calls, or is there a simpler method?

          Cheers.

           Andrew

          Most probably you’ll not receive the file in one shot so will be split between multiple callback calls. Note that file operations must be done in a lower priority task (say 10) so you will need to create such rask and signal from the callback.

          I think I saw an internal FTP client example for m2m, write to ts-emea@telit.com to try to get it.