exchanging files between sd card and server
Dependencies: FTPClient SDFileSystem WIZnetInterface mbed
Fork of FTP_SD_card_wizwikiw7500 by
main.cpp@5:07ae574bbd4c, 2018-02-08 (annotated)
- Committer:
- Dxmanas
- Date:
- Thu Feb 08 06:11:20 2018 +0000
- Revision:
- 5:07ae574bbd4c
- Parent:
- 4:3ccf1cd64c84
qwerty
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" |
Dxmanas | 5:07ae574bbd4c | 4 | //#include "WizFi310Interface.h" |
wiznetw7500 | 0:e35dac7e4c95 | 5 | #include "FTPClient.h" |
wiznetw7500 | 0:e35dac7e4c95 | 6 | #include <string.h> |
wiznetw7500 | 0:e35dac7e4c95 | 7 | #include <stdio.h> |
wiznetw7500 | 0:e35dac7e4c95 | 8 | #define FTP_SERVER_PORT 21 |
Dxmanas | 5:07ae574bbd4c | 9 | |
Dxmanas | 5:07ae574bbd4c | 10 | #define SECURE WizFi310::SEC_WPA2_MIXED |
Dxmanas | 5:07ae574bbd4c | 11 | #define SSID "CDI" |
Dxmanas | 5:07ae574bbd4c | 12 | #define PASS "Cdi*1717" |
wiznetw7500 | 0:e35dac7e4c95 | 13 | static char buf[256]; |
Dxmanas | 4:3ccf1cd64c84 | 14 | |
wiznetw7500 | 0:e35dac7e4c95 | 15 | FTPClient FTP(PB_3, PB_2, PB_1, PB_0, "sd"); // WIZwiki-W7500 |
wiznetw7500 | 0:e35dac7e4c95 | 16 | Serial pc(USBTX, USBRX); |
Dxmanas | 5:07ae574bbd4c | 17 | |
Dxmanas | 5:07ae574bbd4c | 18 | //#if defined(TARGET_WIZwiki_W7500) |
Dxmanas | 5:07ae574bbd4c | 19 | // WizFi310Interface wizfi310(D1, D0, D7, D6, D8, NC, 115200); |
Dxmanas | 5:07ae574bbd4c | 20 | // Serial pc(USBTX, USBRX); |
Dxmanas | 5:07ae574bbd4c | 21 | //#endif |
wiznetw7500 | 0:e35dac7e4c95 | 22 | int main() { |
Dxmanas | 5:07ae574bbd4c | 23 | pc.baud(115200); |
wiznetw7500 | 0:e35dac7e4c95 | 24 | |
wiznetw7500 | 0:e35dac7e4c95 | 25 | pc.printf("------------------------------FTP Client Example-------------------------------------------!\r\n"); |
wiznetw7500 | 0:e35dac7e4c95 | 26 | |
wiznetw7500 | 0:e35dac7e4c95 | 27 | |
Dxmanas | 4:3ccf1cd64c84 | 28 | char ftpServer_control_ip_addr[] = "172.16.126.15"; // FTP Server location |
Dxmanas | 4:3ccf1cd64c84 | 29 | |
akshaytom | 1:b6196ce9efac | 30 | EthernetInterface eth; |
akshaytom | 1:b6196ce9efac | 31 | uint8_t mac_addr[6] = {0x00, 0x08, 0xdc, 0x12, 0x34, 0x45}; |
akshaytom | 1:b6196ce9efac | 32 | char IP_Addr[] = "192.168.0.101"; |
akshaytom | 1:b6196ce9efac | 33 | char IP_Subnet[] = "255.255.255.0"; |
akshaytom | 1:b6196ce9efac | 34 | char IP_Gateway[] = "192.168.0.1"; |
wiznetw7500 | 0:e35dac7e4c95 | 35 | eth.init(mac_addr, IP_Addr, IP_Subnet, IP_Gateway); //Use Static |
wiznetw7500 | 0:e35dac7e4c95 | 36 | eth.connect(); |
Dxmanas | 5:07ae574bbd4c | 37 | //wizfi310.init(mac_addr, IP_Addr, IP_Subnet, IP_Gateway); |
Dxmanas | 5:07ae574bbd4c | 38 | // if ( wizfi310.connect(SECURE, SSID, PASS, WizFi310::WM_STATION)) return -1; |
Dxmanas | 5:07ae574bbd4c | 39 | // printf("After Connect. \r\n"); |
Dxmanas | 5:07ae574bbd4c | 40 | // printf("IP Address is %s\r\n", wizfi310.getIPAddress()); |
akshaytom | 1:b6196ce9efac | 41 | pc.printf("\nThe IP address of the client is %s\r\n",eth.getIPAddress()); |
wiznetw7500 | 0:e35dac7e4c95 | 42 | |
Dxmanas | 4:3ccf1cd64c84 | 43 | //while(1) { |
akshaytom | 1:b6196ce9efac | 44 | pc.printf("\nConnecting...FTPServer\r\nIP:%s, PORT:%d\r\n", ftpServer_control_ip_addr, FTP_SERVER_PORT); |
kulwantt | 3:2b3609dc347a | 45 | |
kulwantt | 3:2b3609dc347a | 46 | /*TO connect to online Server uncomment the below line*/ |
akshaytom | 1:b6196ce9efac | 47 | //FTP.open("demo.wftpserver.com"); |
akshaytom | 1:b6196ce9efac | 48 | |
Dxmanas | 5:07ae574bbd4c | 49 | bool n = FTP.open("192.168.0.100", 21,"FTP","user"); |
Dxmanas | 5:07ae574bbd4c | 50 | //bool n = FTP.open("demo.wftpserver.com", 21,"demo-user","demo-user"); |
akshaytom | 1:b6196ce9efac | 51 | printf("\nThe Files and folders available in the server are :\r\n"); |
wiznetw7500 | 0:e35dac7e4c95 | 52 | FTP.ls(); |
wiznetw7500 | 0:e35dac7e4c95 | 53 | printf("\r\n"); |
akshaytom | 1:b6196ce9efac | 54 | wait(10); |
Dxmanas | 5:07ae574bbd4c | 55 | FTP.getfile("/sd/mbl123.txt","m.txt"); |
wiznetw7500 | 0:e35dac7e4c95 | 56 | printf("The Files in upload folder are :\r\n"); |
wiznetw7500 | 0:e35dac7e4c95 | 57 | FTP.cd("/upload"); |
wiznetw7500 | 0:e35dac7e4c95 | 58 | FTP.ls(); |
Dxmanas | 4:3ccf1cd64c84 | 59 | //FTP.getfile("/sd/bcdef.jpeg","Label.jpeg"); |
Dxmanas | 4:3ccf1cd64c84 | 60 | |
wiznetw7500 | 0:e35dac7e4c95 | 61 | wait(10); |
Dxmanas | 5:07ae574bbd4c | 62 | FTP.putfile("/sd/vlcsnap-3279000.jpg","test.jpg"); |
wiznetw7500 | 0:e35dac7e4c95 | 63 | printf("The Files in download folder are :\r\n"); |
wiznetw7500 | 0:e35dac7e4c95 | 64 | FTP.cd("/download"); |
wiznetw7500 | 0:e35dac7e4c95 | 65 | FTP.ls(); |
wiznetw7500 | 0:e35dac7e4c95 | 66 | printf("\r\n"); |
akshaytom | 1:b6196ce9efac | 67 | wait(10); |
Dxmanas | 4:3ccf1cd64c84 | 68 | // FTP.cd("/image"); |
Dxmanas | 4:3ccf1cd64c84 | 69 | // FTP.ls(); |
kulwantt | 3:2b3609dc347a | 70 | /* |
kulwantt | 3:2b3609dc347a | 71 | To get file from server to client use command "getfile" and to upload file from client to server use command "putfile" |
kulwantt | 3:2b3609dc347a | 72 | //Example of uploading a image file from server to client |
kulwantt | 3:2b3609dc347a | 73 | FTP.getfile("/ftp/vlcsnap-3279000.jpg","vlcsnap-3279000.jpg"); |
kulwantt | 3:2b3609dc347a | 74 | printf("succesfull getting image from server"); |
kulwantt | 3:2b3609dc347a | 75 | */ |
Dxmanas | 4:3ccf1cd64c84 | 76 | //Uploading a text file from server named as m.txt |
Dxmanas | 4:3ccf1cd64c84 | 77 | |
Dxmanas | 4:3ccf1cd64c84 | 78 | //FTP.getfile("/ftp/upload/m.txt","m.txt"); |
Dxmanas | 4:3ccf1cd64c84 | 79 | //FTP.dir(); |
Dxmanas | 4:3ccf1cd64c84 | 80 | //wait(10); |
Dxmanas | 4:3ccf1cd64c84 | 81 | //FTP.cd("/download");*/ |
kulwantt | 3:2b3609dc347a | 82 | //creating directory/folder |
Dxmanas | 4:3ccf1cd64c84 | 83 | //FTP.mkdir("test1"); |
Dxmanas | 4:3ccf1cd64c84 | 84 | //FTP.cd("test1"); |
kulwantt | 3:2b3609dc347a | 85 | //Uploading image file from client that is "sd" card in this case to server |
kulwantt | 3:2b3609dc347a | 86 | //name of image is vlcsnap-3279000.jpg in sd card but will be stored as k.jpg in server |
Dxmanas | 4:3ccf1cd64c84 | 87 | //FTP.putfile("/sd/vlcsnap-3279000.jpg","kl.jpg"); |
Dxmanas | 4:3ccf1cd64c84 | 88 | //FTP.dir(); |
Dxmanas | 4:3ccf1cd64c84 | 89 | //wait(10); |
kulwantt | 3:2b3609dc347a | 90 | //To disconnect the FTP connection |
Dxmanas | 4:3ccf1cd64c84 | 91 | printf("Completed .. you may exit now."); |
kulwantt | 3:2b3609dc347a | 92 | FTP.quit(); |
wiznetw7500 | 0:e35dac7e4c95 | 93 | |
wiznetw7500 | 0:e35dac7e4c95 | 94 | |
Dxmanas | 4:3ccf1cd64c84 | 95 | //} |
wiznetw7500 | 0:e35dac7e4c95 | 96 | } |