Laggger164

ESP32CAM-EthernetFTP

Jul 7th, 2021 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /******************************************************************************
  2. ESP32-CAM remote image access via FTP. Take pictures with ESP32 and upload it via FTP making it accessible for the outisde network.
  3. Leonardo Bispo
  4. July - 2019
  5. https://github.com/ldab/ESP32_FTPClient
  6. Distributed as-is; no warranty is given.
  7. ******************************************************************************/
  8. #include "Arduino.h"
  9. #include <Ethernet.h>
  10. #include <EthernetClient.h>
  11. #include "ESP32_FTPClient.h"
  12. #include "octocat.h"
  13. #include <SPI.h>
  14.  
  15.  
  16. // Enter a MAC address for your controller below.
  17. // Newer Ethernet shields have a MAC address printed on a sticker on the shield
  18. byte mac[] = {
  19.   0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
  20. };
  21.  
  22. char ftp_server[] = "";
  23. char ftp_user[]   = "";
  24. char ftp_pass[]   = "";
  25.  
  26. // you can pass a FTP timeout and debbug mode on the last 2 arguments
  27. ESP32_FTPClient ftp (ftp_server,ftp_user,ftp_pass, 5000, 2);
  28.  
  29. void setup()
  30. {
  31.   Serial.begin( 115200 );
  32.  
  33.   Ethernet.init(15);  // ESP32CAM SCS (chip select pin, 15 and 2 work for sure)
  34.  
  35.   SPI.begin(14,12,13,15); //SCLK,MISO,MOSI,SCS(same as Ethernet.init())
  36.  
  37.   // start the Ethernet connection:
  38.   Serial.println("Initialize Ethernet with DHCP:");
  39.   if (Ethernet.begin(mac) == 0) {
  40.     Serial.println("Failed to configure Ethernet using DHCP");
  41.     if (Ethernet.hardwareStatus() == EthernetNoHardware) {
  42.       Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
  43.     } else if (Ethernet.linkStatus() == LinkOFF) {
  44.       Serial.println("Ethernet cable is not connected.");
  45.     }
  46.     // no point in carrying on, so do nothing forevermore:
  47.     while (true) {
  48.       delay(1);
  49.     }
  50.   }
  51.   // print your local IP address:
  52.   Serial.print("My IP address: ");
  53.   Serial.println(Ethernet.localIP());
  54.   ftp.OpenConnection();
  55.  
  56.   // Get directory content
  57.   ftp.InitFile("Type A");
  58.   String list[128];
  59.   ftp.ChangeWorkDir("/public_html/zyro/gallery_gen/");
  60.   ftp.ContentList("", list);
  61.   Serial.println("\nDirectory info: ");
  62.   for(int i = 0; i < sizeof(list); i++)
  63.   {
  64.     if(list[i].length() > 0)
  65.       Serial.println(list[i]);
  66.     else
  67.       break;
  68.   }
  69.  
  70.   // Make a new directory
  71.   ftp.InitFile("Type A");
  72.   ftp.MakeDir("my_new_dir");
  73.  
  74.   // Create the new file and send the image
  75.   ftp.ChangeWorkDir("my_new_dir");
  76.   ftp.InitFile("Type I");
  77.   ftp.NewFile("octocat.jpg");
  78.   ftp.WriteData( octocat_pic, sizeof(octocat_pic) );
  79.   ftp.CloseFile();
  80.  
  81.   // Create the file new and write a string into it
  82.   ftp.InitFile("Type A");
  83.   ftp.NewFile("hello_world.txt");
  84.   ftp.Write("Hello World");
  85.   ftp.CloseFile();
  86.  
  87.   ftp.CloseConnection();
  88. }
  89.  
  90. void loop()
  91. {
  92.  
  93. }
Add Comment
Please, Sign In to add comment