understanding how to do FTP transfers with GSM/GPRS shield

Hi, I have been having a number of issues trying to get FTP uploads/downloads to work from an FTP server using AT commands and a GSM/GPRS shield (SIM900) - i have a tried a lot of example code but nothing seems to work so i have decided to go back to squar 1 and explain what exacly i am doing and see if poeple think makes logical sence or whether my aproach is completely flawed.

As i understand it the FTP process requires two channels - one channel for data and the other channel for commands.

So....

1) Attempt to open a TCP connection to the ftp server on port 80 with the correct APN, username and password using the relavant AT commands.

2) Once a connection is made attempt to open an FTP session on port 21 with the correct APN, username and password (same as above) using the relavent AT comands.

Does this seem like the right aproach or am i way off here.

I can get the first part to work and i can even send test data to the server although i have no idea where the data goes as there doesnt to be anywhere for it to go as i havent explicity told it to it where to go i just get a message back from the shield saying that the data has been sent.

The second part always fails due to a timeout error.

Initially i did it without setting up the TCP connection but then it seemed to me that this wouldnt work since there was no data connection.

Any help/guidance here would be much appeciated.

Cheers.

Is it necessary to use FTP? HTTP would be much easier; POST uploads only require a single TCP connection.

Hi Chagrin, Thanks for the reply. No i dont have to use FTP i just assumed i had to because i am dealing with an ftp server - as you can tell my knowledge of this stuff is limited. Basically i just want to be able to upload a file to an ftp server but so far i have failed to get this to work so any suggestions or examples you have would be great.

Any help is much appreciated.

Cheers.

katesfb: 1) Attempt to open a TCP connection to the ftp server on port 80 with the correct APN, username and password using the relavant AT commands.

2) Once a connection is made attempt to open an FTP session on port 21 with the correct APN, username and password (same as above) using the relavent AT comands.

Does this seem like the right aproach or am i way off here.

That doesn't sound anything like FTP. Why is port 80 involved at all? Are you trying to use active or passive mode FTP, what sequence of commands are you sending and what responses are you receiving? You can't simply open a couple of sockets, there is far more to it than that. Additionally, FTP inherently requires two concurrent socket connections and you need to confirm that your communication device supports that.

Hi PeterH, And thanks for the reply - as you can tell i am not really sure what i am doing. The device i am using is a GSM/GPRS shield from Seeedstudio which is apparetnly able to do FTP as well as HTTP etc. I am trying to do passive mode FTP. I only tried to use a TCP connection because every thing else failed - ironically that bit worked.

I can do SMS using the AT comands no prblem and i can connect to the ftp sever using a TCP socket as well, havent tried HTTP as yet which is apparently easier as it only requires a TCP connection.

I can do FTP transfers over a network using a dedicated library like the FTP library that is used with the processing IDE which indicates that username, password, etc are all correct.

Anyway... these are the command sequences that i have tried in the past to do FTP along with the responses - this is for an FTP get;

AT

OK
AT+CSQ

+CSQ: 23,0

OK
AT+CGATT?

+CGATT: 1

OK
AT+CSTT

OK
AT+SAPBR=3,1,"CONTYPE","GPRS"

OK
AT+SAPBR=3,1,"APN","internet"

OK
AT+SAPBR=1,1

OK
AT+FTPCID=1

OK
AT+FTPMODE=1

OK
AT+FTPTYPE="A"

OK
AT+FTPSERV="ftp.xxxx.xx.xx"

OK
AT+FTPUN="user"

OK
AT+FTPPW="pass"

OK
AT+FTPGETNAME="test.log"

OK
AT+FTPGETPATH="/file/path"

OK
AT+FTPGET=1

OK

+FTPGET:1,64
AT+FTPGET=2,1024

+CME ERROR: operation not allowed

It always seems to fail at the same place and it doesnt matter wether its a PUT or a GET operation. Sometimes i get the 61 error (network error) but mostly its 64 (timeout error).

Any help you can give is very much appreciated as i have been banging my head aganist a wall with this.

Cheers.

See if this link helps: http://www.edaboard.com/thread277914.html#post1195657

Hi Wanderson, and thanks for the reply. Yes i have tried this code and variations of it the result is the same - fails at;

AT+FTPGET=1

with response; +FTPGET:1,64

Which is again the timeout error.

The AT sequence as written also fails at;

AT+CIICR with response; +PDP Deact

How ever if i put in; at+cstt="internet","username","password" before this command then it works only to fail later on at;

AT+FTPGET=1 again.

Any ideas?

Any help is much appreciated.

Cheers.

Since you’re using the AT interface for this, the modem is doing all the protocol work so you need to know what the modem is capable of (it looks as if it supports an FTP AT extension) and ideally you would also have examples showing how to use them. You will need to select the operating mode (active/passive) and the transfer encoding (text/binary) and you might need to do this at the right point in the command sequence.

FTP is a text-based protocol and most text-based FTP clients have a command syntax that maps pretty directly to the FTP protocol. I would expect to find that your AT extension does too. That being the case I suggest you look for an AT command sequence that will get data from the FTP server without requiring a file transfer - such as changing the directory, and listing files in that directory, to confirm you’re able to talk to the FTP server at all, before you start trying to transfer files. Hopefully the modem will come with examples showing how to do that sort of thing, but if not then trial and error will take you a long way once you know the set of FTP AT command extensions and can see how they relate to the FTP protocol. You will probably find it useful to have a play with a command-line FTP client so that you can see how simple the protocol is. It is only the commands for transferring files that need the data connection so you can do quite a lot just using a telnet client to connect to the FTP control port and typing the FTP protocol commands in manually so you can understand exactly what’s happening over the wire.