It helps how to upload file from client(sd card connected with wizwiki-w7500) to server(FTP) and vice-versa.
Dependencies: FTPClient SDFileSystem WIZnetInterface mbed
Fork of FTP_Client_Configuration by
main.cpp@3:2b3609dc347a, 2018-01-03 (annotated)
- Committer:
- kulwantt
- Date:
- Wed Jan 03 11:01:52 2018 +0000
- Revision:
- 3:2b3609dc347a
- Parent:
- 2:a185787cdddf
tdryrh
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]; |
kulwantt | 3:2b3609dc347a | 9 | DigitalIn P1(D2); |
wiznetw7500 | 2:a185787cdddf | 10 | static char ID[]={"FTP"}; //Set FTPServer Login ID |
kulwantt | 3:2b3609dc347a | 11 | static char PASSWORD[]={"user"}; //user //Set FTPServer Login Password |
wiznetw7500 | 0:e35dac7e4c95 | 12 | FTPClient FTP(PB_3, PB_2, PB_1, PB_0, "sd"); // WIZwiki-W7500 |
wiznetw7500 | 0:e35dac7e4c95 | 13 | Serial pc(USBTX, USBRX); |
wiznetw7500 | 0:e35dac7e4c95 | 14 | int main() { |
wiznetw7500 | 0:e35dac7e4c95 | 15 | pc.baud(9600); |
wiznetw7500 | 0:e35dac7e4c95 | 16 | |
wiznetw7500 | 0:e35dac7e4c95 | 17 | pc.printf("------------------------------FTP Client Example-------------------------------------------!\r\n"); |
wiznetw7500 | 0:e35dac7e4c95 | 18 | |
wiznetw7500 | 0:e35dac7e4c95 | 19 | |
wiznetw7500 | 2:a185787cdddf | 20 | char ftpServer_control_ip_addr[] = "192.168.0.100"; // FTP Server location |
wiznetw7500 | 2:a185787cdddf | 21 | char* userid = "FTP"; //FTP Server User ID |
wiznetw7500 | 2:a185787cdddf | 22 | char* pass = "user"; //FTP Server Password |
akshaytom | 1:b6196ce9efac | 23 | EthernetInterface eth; |
akshaytom | 1:b6196ce9efac | 24 | uint8_t mac_addr[6] = {0x00, 0x08, 0xdc, 0x12, 0x34, 0x45}; |
akshaytom | 1:b6196ce9efac | 25 | char IP_Addr[] = "192.168.0.101"; |
akshaytom | 1:b6196ce9efac | 26 | char IP_Subnet[] = "255.255.255.0"; |
akshaytom | 1:b6196ce9efac | 27 | char IP_Gateway[] = "192.168.0.1"; |
wiznetw7500 | 0:e35dac7e4c95 | 28 | eth.init(mac_addr, IP_Addr, IP_Subnet, IP_Gateway); //Use Static |
wiznetw7500 | 0:e35dac7e4c95 | 29 | eth.connect(); |
akshaytom | 1:b6196ce9efac | 30 | pc.printf("\nThe IP address of the client is %s\r\n",eth.getIPAddress()); |
wiznetw7500 | 0:e35dac7e4c95 | 31 | |
kulwantt | 3:2b3609dc347a | 32 | while(1) { |
akshaytom | 1:b6196ce9efac | 33 | pc.printf("\nConnecting...FTPServer\r\nIP:%s, PORT:%d\r\n", ftpServer_control_ip_addr, FTP_SERVER_PORT); |
kulwantt | 3:2b3609dc347a | 34 | |
kulwantt | 3:2b3609dc347a | 35 | /*TO connect to online Server uncomment the below line*/ |
akshaytom | 1:b6196ce9efac | 36 | //FTP.open("demo.wftpserver.com"); |
akshaytom | 1:b6196ce9efac | 37 | |
akshaytom | 1:b6196ce9efac | 38 | bool n = FTP.open("192.168.0.100", 21,"FTP","user"); |
kulwantt | 3:2b3609dc347a | 39 | |
akshaytom | 1:b6196ce9efac | 40 | printf("\nThe Files and folders available in the server are :\r\n"); |
wiznetw7500 | 0:e35dac7e4c95 | 41 | FTP.ls(); |
wiznetw7500 | 0:e35dac7e4c95 | 42 | printf("\r\n"); |
akshaytom | 1:b6196ce9efac | 43 | wait(10); |
wiznetw7500 | 0:e35dac7e4c95 | 44 | printf("The Files in upload folder are :\r\n"); |
wiznetw7500 | 0:e35dac7e4c95 | 45 | FTP.cd("/upload"); |
wiznetw7500 | 0:e35dac7e4c95 | 46 | FTP.ls(); |
wiznetw7500 | 0:e35dac7e4c95 | 47 | wait(10); |
wiznetw7500 | 0:e35dac7e4c95 | 48 | printf("The Files in download folder are :\r\n"); |
wiznetw7500 | 0:e35dac7e4c95 | 49 | FTP.cd("/download"); |
wiznetw7500 | 0:e35dac7e4c95 | 50 | FTP.ls(); |
wiznetw7500 | 0:e35dac7e4c95 | 51 | printf("\r\n"); |
akshaytom | 1:b6196ce9efac | 52 | wait(10); |
kulwantt | 3:2b3609dc347a | 53 | FTP.cd("/image"); |
kulwantt | 3:2b3609dc347a | 54 | FTP.ls(); |
kulwantt | 3:2b3609dc347a | 55 | /* |
kulwantt | 3:2b3609dc347a | 56 | To get file from server to client use command "getfile" and to upload file from client to server use command "putfile" |
kulwantt | 3:2b3609dc347a | 57 | //Example of uploading a image file from server to client |
kulwantt | 3:2b3609dc347a | 58 | FTP.getfile("/ftp/vlcsnap-3279000.jpg","vlcsnap-3279000.jpg"); |
kulwantt | 3:2b3609dc347a | 59 | printf("succesfull getting image from server"); |
kulwantt | 3:2b3609dc347a | 60 | */ |
kulwantt | 3:2b3609dc347a | 61 | //Uploading a text file from server named as k.txt |
kulwantt | 3:2b3609dc347a | 62 | FTP.getfile("/ftp/k.txt","k.txt"); |
kulwantt | 3:2b3609dc347a | 63 | FTP.dir(); |
kulwantt | 3:2b3609dc347a | 64 | wait(10); |
kulwantt | 3:2b3609dc347a | 65 | FTP.cd("/download"); |
kulwantt | 3:2b3609dc347a | 66 | //creating directory/folder |
kulwantt | 3:2b3609dc347a | 67 | FTP.mkdir("test1"); |
kulwantt | 3:2b3609dc347a | 68 | FTP.cd("test1"); |
kulwantt | 3:2b3609dc347a | 69 | //Uploading image file from client that is "sd" card in this case to server |
kulwantt | 3:2b3609dc347a | 70 | //name of image is vlcsnap-3279000.jpg in sd card but will be stored as k.jpg in server |
kulwantt | 3:2b3609dc347a | 71 | FTP.putfile("/sd/vlcsnap-3279000.jpg","k.jpg"); |
kulwantt | 3:2b3609dc347a | 72 | FTP.dir(); |
kulwantt | 3:2b3609dc347a | 73 | wait(10); |
kulwantt | 3:2b3609dc347a | 74 | //To disconnect the FTP connection |
kulwantt | 3:2b3609dc347a | 75 | FTP.quit(); |
wiznetw7500 | 0:e35dac7e4c95 | 76 | |
wiznetw7500 | 0:e35dac7e4c95 | 77 | |
kulwantt | 3:2b3609dc347a | 78 | } |
wiznetw7500 | 0:e35dac7e4c95 | 79 | } |