This article is about showing you how to upload a file and download a file form a web server using FTP protocol. SIM900 GSM module provides a set of AT commands which can be used for creating, uploading and downloading a file through a GPRS connection.

Watch this video if you want to see the live demo,

To communicate with a web server using a FTP account we need a username and password  for logging in. In this example i am using my Linux shared hosting which i had purchased for my old company website. If you are having a cPanel software installed on your server you can easily create a FTP account for uploading and downloading a file.

Here is the screen shot of my FTP login credentials,

In the above image you can see that my FTP username is This email address is being protected from spambots. You need JavaScript enabled to view it. and FTP server name is ftp.marsinnovations.in 

The password which i had set is valetron 

Using the above details i can upload and download any file in my web server.

Once you have all these details, you can start by first setting up the GPRS connection as follows, 


 Setting up GPRS connection

Set the connection type to GPRS

AT+SAPBR=3,1,"Contype","GPRS"

OK

Set the APN to to "www" since i am using a Vodafone SIM card, It might be different for you, and depends on the network

AT+SAPBR=3,1,"APN","www"

OK

Enable the GPRS

AT+SAPBR =1,1

OK

Query if the connection is setup properly, if we get back a IP address then we can proceed

AT+SAPBR=2,1

+SAPBR: 1,1,"10.50.210.158"

OK


 Uploading a file to the server

We were allocated a IP address and now we can proceed further by setting up the FTP bearer profile identifier

AT+FTPCID=1

OK

Set the FTP server name to which we want to connect, which in my case is ftp.marsinnovations.in

AT+FTPSERV="ftp.marsinnovations.in"

OK

Set the FTP user name, which in my case is This email address is being protected from spambots. You need JavaScript enabled to view it.

AT+FTPUN="This email address is being protected from spambots. You need JavaScript enabled to view it."

OK

Set the FTP password for logging in, which in my case is valetron

AT+FTPPW="valetron"

OK

Set the file name which we want to upload to the server, which in my case is 1K.txt

AT+FTPPUTNAME="1K.txt"

OK

Set the path where the file needs to be uploaded, Here a forward slash ("/") means we are uploading to the root directory of my FTP account

AT+FTPPUTPATH="/"

OK

Start the FTP put session, by giving this command

AT+FTPPUT=1

OK

The below output from module indicates it is ready for data upload and 1248 is the max length of data that can be sent at a time, It depends on network status

+FTPPUT:1,1,1248

The below command tells the module that we want to send 10 bytes of data

AT+FTPPUT=2,10

The below URC means that it is ready to accept data and we have to start typing in the data. In my case, i have typed Hello12345

+FTPPUT:2,10

Hello12345

The OK response means that it has received the data

OK

The below URC means that it is ready to transfer more data

+FTPPUT:1,1,1248

But we don't want to transfer more data, So we close the FTP put session by the below command

AT+FTPPUT=2,0

OK

+FTPPUT:1,0

By now should be able to see a file named 1K.txt in your server FTP account root directory with the content Hello12345


 Downloading a file from the server

For simplicity we will download the same file we uploaded earlier 

We were allocated a IP address and now we can proceed further by setting up the FTP bearer profile identifier

AT+FTPCID=1

OK

Set the FTP server name to which we want to connect, which in my case is ftp.marsinnovations.in

AT+FTPSERV="ftp.marsinnovations.in"

OK

Set the FTP user name, which in my case is This email address is being protected from spambots. You need JavaScript enabled to view it.

AT+FTPUN="This email address is being protected from spambots. You need JavaScript enabled to view it."

OK

Set the FTP password for logging in, which in my case is valetron

AT+FTPPW="valetron"

OK

Set the file name which we want to download from the server, which is 1K.txt

AT+FTPGETNAME="1K.txt"

OK

Set the path from where the file needs to be downloaded, Here a forward slash ("/") means we are downloading from the root directory of my FTP account

AT+FTPGETPATH="/"

OK

Start the FTP get session, by giving this command

AT+FTPGET=1

OK

The below URC means that data is received and is available for reading

+FTPGET:1,1

The below command instructs the module to read 1024 bytes of data, if there is lesser bytes of data available then it only gives us that much amount of data

AT+FTPGET=2,1024

The below URC means that 10 bytes of data was read, which is printed below as Hello12345, which is the content of the file 1K.txt 

 

+FTPGET:2,10

Hello12345

OK

The below URC means that FTP server session is closed

+FTPGET:1,0


 

This is how you upload and download files via FTP in SIM900 and SIM800 GSM module also. 

Hope it helps someone. 

Also see:

 




About the Author

is the author of this blog and is an Embedded systems design engineer by profession & Founder @ Valetron Systems Pvt Ltd


Email:This email address is being protected from spambots. You need JavaScript enabled to view it.

Find us on Google+

HIRE ME FOR YOUR PROJECT AS A FREELANCER

 

EasyEDA: Free Circuit Design Software

  • Easy Schematic Capture
  • Powerful Circuit Simulation
  • Online PCB design

Design Your Circuit and PCB here:

https://easyeda.com/editor

PCB Prototype Manufacturer - JLCPCB

Electronic Components Online Store