![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ftp server and client using Wizfi310
Dependencies: FTPClient SDFileSystem WizFi310Interface_Legacynew mbed
Fork of Manas_FTP_SD_card_wizwikiw7500 by
main.cpp@4:3ccf1cd64c84, 2018-01-31 (annotated)
- Committer:
- Dxmanas
- Date:
- Wed Jan 31 02:54:37 2018 +0000
- Revision:
- 4:3ccf1cd64c84
- Parent:
- 3:2b3609dc347a
- Child:
- 5:13323caa45d6
program to exchange files between sd card and local server (ALFTP) and also online server
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wiznetw7500 | 0:e35dac7e4c95 | 1 | #include "mbed.h" |
wiznetw7500 | 0:e35dac7e4c95 | 2 | #include "SDFileSystem.h" |
wiznetw7500 | 0:e35dac7e4c95 | 3 | #include "EthernetInterface.h" |
wiznetw7500 | 0:e35dac7e4c95 | 4 | #include "FTPClient.h" |
wiznetw7500 | 0:e35dac7e4c95 | 5 | #include <string.h> |
wiznetw7500 | 0:e35dac7e4c95 | 6 | #include <stdio.h> |
wiznetw7500 | 0:e35dac7e4c95 | 7 | #define FTP_SERVER_PORT 21 |
wiznetw7500 | 0:e35dac7e4c95 | 8 | static char buf[256]; |
Dxmanas | 4:3ccf1cd64c84 | 9 | |
wiznetw7500 | 0:e35dac7e4c95 | 10 | FTPClient FTP(PB_3, PB_2, PB_1, PB_0, "sd"); // WIZwiki-W7500 |
wiznetw7500 | 0:e35dac7e4c95 | 11 | Serial pc(USBTX, USBRX); |
wiznetw7500 | 0:e35dac7e4c95 | 12 | int main() { |
Dxmanas | 4:3ccf1cd64c84 | 13 | pc.baud(9600); |
wiznetw7500 | 0:e35dac7e4c95 | 14 | |
wiznetw7500 | 0:e35dac7e4c95 | 15 | pc.printf("------------------------------FTP Client Example-------------------------------------------!\r\n"); |
wiznetw7500 | 0:e35dac7e4c95 | 16 | |
wiznetw7500 | 0:e35dac7e4c95 | 17 | |
Dxmanas | 4:3ccf1cd64c84 | 18 | char ftpServer_control_ip_addr[] = "172.16.126.15"; // FTP Server location |
Dxmanas | 4:3ccf1cd64c84 | 19 | |
akshaytom | 1:b6196ce9efac | 20 | EthernetInterface eth; |
akshaytom | 1:b6196ce9efac | 21 | uint8_t mac_addr[6] = {0x00, 0x08, 0xdc, 0x12, 0x34, 0x45}; |
akshaytom | 1:b6196ce9efac | 22 | char IP_Addr[] = "192.168.0.101"; |
akshaytom | 1:b6196ce9efac | 23 | char IP_Subnet[] = "255.255.255.0"; |
akshaytom | 1:b6196ce9efac | 24 | char IP_Gateway[] = "192.168.0.1"; |
wiznetw7500 | 0:e35dac7e4c95 | 25 | eth.init(mac_addr, IP_Addr, IP_Subnet, IP_Gateway); //Use Static |
wiznetw7500 | 0:e35dac7e4c95 | 26 | eth.connect(); |
akshaytom | 1:b6196ce9efac | 27 | pc.printf("\nThe IP address of the client is %s\r\n",eth.getIPAddress()); |
wiznetw7500 | 0:e35dac7e4c95 | 28 | |
Dxmanas | 4:3ccf1cd64c84 | 29 | //while(1) { |
akshaytom | 1:b6196ce9efac | 30 | pc.printf("\nConnecting...FTPServer\r\nIP:%s, PORT:%d\r\n", ftpServer_control_ip_addr, FTP_SERVER_PORT); |
kulwantt | 3:2b3609dc347a | 31 | |
kulwantt | 3:2b3609dc347a | 32 | /*TO connect to online Server uncomment the below line*/ |
akshaytom | 1:b6196ce9efac | 33 | //FTP.open("demo.wftpserver.com"); |
akshaytom | 1:b6196ce9efac | 34 | |
Dxmanas | 4:3ccf1cd64c84 | 35 | //bool n = FTP.open("192.168.0.100", 21,"FTP","user"); |
Dxmanas | 4:3ccf1cd64c84 | 36 | bool n = FTP.open("demo.wftpserver.com", 21,"demo-user","demo-user"); |
akshaytom | 1:b6196ce9efac | 37 | printf("\nThe Files and folders available in the server are :\r\n"); |
wiznetw7500 | 0:e35dac7e4c95 | 38 | FTP.ls(); |
wiznetw7500 | 0:e35dac7e4c95 | 39 | printf("\r\n"); |
akshaytom | 1:b6196ce9efac | 40 | wait(10); |
Dxmanas | 4:3ccf1cd64c84 | 41 | //FTP.getfile("/sd/mbl123.txt","m.txt"); |
wiznetw7500 | 0:e35dac7e4c95 | 42 | printf("The Files in upload folder are :\r\n"); |
wiznetw7500 | 0:e35dac7e4c95 | 43 | FTP.cd("/upload"); |
wiznetw7500 | 0:e35dac7e4c95 | 44 | FTP.ls(); |
Dxmanas | 4:3ccf1cd64c84 | 45 | //FTP.getfile("/sd/bcdef.jpeg","Label.jpeg"); |
Dxmanas | 4:3ccf1cd64c84 | 46 | |
wiznetw7500 | 0:e35dac7e4c95 | 47 | wait(10); |
Dxmanas | 4:3ccf1cd64c84 | 48 | //FTP.putfile("/sd/vlcsnap-3279000.jpg","manas2.jpg"); |
wiznetw7500 | 0:e35dac7e4c95 | 49 | printf("The Files in download folder are :\r\n"); |
wiznetw7500 | 0:e35dac7e4c95 | 50 | FTP.cd("/download"); |
wiznetw7500 | 0:e35dac7e4c95 | 51 | FTP.ls(); |
wiznetw7500 | 0:e35dac7e4c95 | 52 | printf("\r\n"); |
akshaytom | 1:b6196ce9efac | 53 | wait(10); |
Dxmanas | 4:3ccf1cd64c84 | 54 | // FTP.cd("/image"); |
Dxmanas | 4:3ccf1cd64c84 | 55 | // FTP.ls(); |
kulwantt | 3:2b3609dc347a | 56 | /* |
kulwantt | 3:2b3609dc347a | 57 | To get file from server to client use command "getfile" and to upload file from client to server use command "putfile" |
kulwantt | 3:2b3609dc347a | 58 | //Example of uploading a image file from server to client |
kulwantt | 3:2b3609dc347a | 59 | FTP.getfile("/ftp/vlcsnap-3279000.jpg","vlcsnap-3279000.jpg"); |
kulwantt | 3:2b3609dc347a | 60 | printf("succesfull getting image from server"); |
kulwantt | 3:2b3609dc347a | 61 | */ |
Dxmanas | 4:3ccf1cd64c84 | 62 | //Uploading a text file from server named as m.txt |
Dxmanas | 4:3ccf1cd64c84 | 63 | |
Dxmanas | 4:3ccf1cd64c84 | 64 | //FTP.getfile("/ftp/upload/m.txt","m.txt"); |
Dxmanas | 4:3ccf1cd64c84 | 65 | //FTP.dir(); |
Dxmanas | 4:3ccf1cd64c84 | 66 | //wait(10); |
Dxmanas | 4:3ccf1cd64c84 | 67 | //FTP.cd("/download");*/ |
kulwantt | 3:2b3609dc347a | 68 | //creating directory/folder |
Dxmanas | 4:3ccf1cd64c84 | 69 | //FTP.mkdir("test1"); |
Dxmanas | 4:3ccf1cd64c84 | 70 | //FTP.cd("test1"); |
kulwantt | 3:2b3609dc347a | 71 | //Uploading image file from client that is "sd" card in this case to server |
kulwantt | 3:2b3609dc347a | 72 | //name of image is vlcsnap-3279000.jpg in sd card but will be stored as k.jpg in server |
Dxmanas | 4:3ccf1cd64c84 | 73 | //FTP.putfile("/sd/vlcsnap-3279000.jpg","kl.jpg"); |
Dxmanas | 4:3ccf1cd64c84 | 74 | //FTP.dir(); |
Dxmanas | 4:3ccf1cd64c84 | 75 | //wait(10); |
kulwantt | 3:2b3609dc347a | 76 | //To disconnect the FTP connection |
Dxmanas | 4:3ccf1cd64c84 | 77 | printf("Completed .. you may exit now."); |
kulwantt | 3:2b3609dc347a | 78 | FTP.quit(); |
wiznetw7500 | 0:e35dac7e4c95 | 79 | |
wiznetw7500 | 0:e35dac7e4c95 | 80 | |
Dxmanas | 4:3ccf1cd64c84 | 81 | //} |
wiznetw7500 | 0:e35dac7e4c95 | 82 | } |