VC0706 camera + FTP + MQTT

Fork of FTPClient by Akshay Tom

Files at this revision

API Documentation at this revision

Comitter:
Albinarackal
Date:
Mon Jul 16 09:20:12 2018 +0000
Parent:
4:8ecc32e7c69b
Commit message:
Program for VC0706 with FTP and MQTT

Changed in this revision

FTPClient.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 8ecc32e7c69b -r 7d5a68d42a0b FTPClient.cpp
--- a/FTPClient.cpp	Thu Dec 14 04:49:35 2017 +0000
+++ b/FTPClient.cpp	Mon Jul 16 09:20:12 2018 +0000
@@ -2,6 +2,7 @@
 #include "EthernetInterface.h"
 #include "FTPClient.h"
 //#define DEBUG
+int count=0;
 FTPClient::FTPClient(PinName mosi, PinName miso, PinName sclk, PinName ssel, const char* root) : _SDFileSystem(mosi, miso, sclk, ssel, root){
     //printf("Object");
     blogin = false;
@@ -21,23 +22,30 @@
 
 bool FTPClient::open(char ip[], int port, char id[], char pass[]){
     //printf("\nInside Open");
-/*
-      printf("\n%s",ip);
+
+   /*   printf("\n%s",ip);
       printf("\n%d",port);
       printf("\n%s",id);
       printf("\n%s",pass);
-      printf("\nHappens");
-      printf("\nHappens\n");
+      //printf("\nHappens");
+     // printf("\nHappens\n");
   */
     
     FTPClientControlSock = new TCPSocketConnection();
     FTPClientDataSock = new TCPSocketConnection();
-    //printf("\nHappens\n");
+   /* printf("\nHappens\n");
+    printf("after loop first");
+    printf("after loop first");
+    printf("after loop first");
+    printf("after loop first");
+    printf("after loop first");*/
     #if 0
     do{
         FTPClientControlSock->connect(ip, port);
     }while(!FTPClientControlSock->is_connected());
     #endif
+    
+    
     #if 1
     while (FTPClientControlSock->connect(ip, port) < 0) {
     #ifdef DEBUG
@@ -47,6 +55,7 @@
     }
     #endif
     
+    
     while(!blogin){
         size = FTPClientControlSock->receive(rbuf, sizeof(rbuf));
         if(size > 0){
@@ -70,6 +79,7 @@
             }
         }  
     }
+   // printf("end of the open port");
     return 1;
 }
 //*/
@@ -157,7 +167,7 @@
                         else{
                             brfileflag = true;
                             fclose(fp);
-                            FTPClientDataSock->close();
+                            //FTPClientDataSock->close();
                             break;
                         }
                     }
@@ -190,6 +200,7 @@
     else return 0;
 }
 bool FTPClient::putfile(char* myfilename, char* filename){
+   printf("Entered putfile\n"); 
     
     if(blogin){
         
@@ -197,16 +208,25 @@
         FTPClientControlSock->send(sbuf, strlen(sbuf));
         
         while(!bsfileflag){
+           // printf("THE VALUE OF RbuF is  : %s\n",rbuf);
+            /*if(!strncmp(rbuf,"220",3)){
+            bool status = FTPClient::open("172.16.73.33", 21,"user1","user1");
+            printf("THE VALUE OF RbuF is  : %s\n",rbuf);
+            printf("THE STATUS IS : %d\n",status);
+            }*/
+           
             size = FTPClientControlSock->receive(rbuf, sizeof(rbuf));
             if(size > 0){
-            #ifdef DEBUG
-                printf("Received message from server: %s\r\n", rbuf);
-            #endif
+           //#ifdef DEBUG
+                printf("Received message from server after loading the file in putfile      : %s\r\n", rbuf);
+            //#endif
                 if (!strncmp(rbuf, "150", 3)){
+                    printf("ENTERING TO UPDATE FILE TO SERVER\n");
                     fp = fopen(myfilename, "r"); 
                     fseek(fp, 0, SEEK_END);            // seek to end of file
                     remain_filesize = ftell(fp);       // get current file pointer
                     fseek(fp, 0, SEEK_SET);            // seek back to beginning of file  
+                  //printf("the beg of fl: %d\n",fseek(fp, 0, SEEK_SET) );  
                     do{
                         memset(sbuf, 0, sizeof(sbuf));
                         if(remain_filesize > MAX_SS)
@@ -222,10 +242,12 @@
                     }while(remain_filesize!=0);
                     fclose(fp); 
                     bsfileflag = true;
-                    FTPClientDataSock->close();
+                    printf("ENTER TO CLOSE FTPdatasocket\n");
+                    //FTPClientDataSock->close();
                     break;
                 }
                 else if (!strncmp(rbuf, "227", 3)){
+                    printf("while\n");
                     pportc(rbuf); 
                 #if 0
                     do{
@@ -235,9 +257,10 @@
                     
                 #if 1
                     while (FTPClientDataSock->connect(ftpServer_data_ip_addr_str, remote_port) < 0) {
-                    #ifdef DEBUG
+                        
+                    //#ifdef DEBUG
                         printf("Unable to connect to (%s) on port (%d)\r\n", ftpServer_data_ip_addr_str, remote_port);
-                    #endif
+                    //#endif
                         wait(1);
                     }
                 #endif  
@@ -245,6 +268,7 @@
                     FTPClientControlSock->send(sbuf, strlen(sbuf));  
                 }
             }  
+        
         }
         bsfileflag = false;
         return 1;
@@ -270,11 +294,11 @@
                         size = FTPClientDataSock->receive(rbuf, sizeof(rbuf));
                         rbuf[size] = '\0';
                         if(size>0){
-                            printf("%s", rbuf);
+                            printf("The buf val is :%s\n", rbuf);
                         }
                         else{
                             bdirflag = true;
-                            FTPClientDataSock->close();
+                            //FTPClientDataSock->close();
                             break;
                         }
                     }  
@@ -313,27 +337,40 @@
         FTPClientControlSock->send(sbuf, strlen(sbuf));
         
         while(!blsflag){
+            //rbuf[size] = '\0';
             size = FTPClientControlSock->receive(rbuf, sizeof(rbuf));
             if(size > 0){
-            #ifdef DEBUG
-                printf("Received message from server: %s\r\n", rbuf);
-            #endif
+            //#ifdef DEBUG
+             printf("ls started\n");
+                printf("Received message from server: %s\n", rbuf);
+            //#endif
                 if (!strncmp(rbuf, "150", 3)){
                     while(true){
                         memset(rbuf, 0, sizeof(rbuf));
                         size = FTPClientDataSock->receive(rbuf, sizeof(rbuf));
-                        rbuf[size] = '\0';
+                       // rbuf[size] = '\0';
+                        printf("size value is : %d\n",size);
                         if(size>0){
-                            printf("%s", rbuf);
+                            printf(" Image NAME %s\n", rbuf);
+                            printf("Image list\n");
+                           
                         }
+                       
                         else{
+                             printf("else started\n");
                             blsflag = true;
-                            FTPClientDataSock->close();
+                             //count++;
+                            //FTPClientDataSock->close();
+                             printf("else ended\n");
                             break;
+                            
                         }
+                     
                     }  
                 }
+                
                 else if (!strncmp(rbuf, "227", 3)){
+                    printf("else if ended\n");
                     pportc(rbuf); 
                 #if 0
                     do{
@@ -342,17 +379,22 @@
                 #endif
                 #if 1
                     while (FTPClientDataSock->connect(ftpServer_data_ip_addr_str, remote_port) < 0) {
-                    #ifdef DEBUG
+                    //#ifdef DEBUG
                         printf("Unable to connect to (%s) on port (%d)\r\n", ftpServer_data_ip_addr_str, remote_port);
-                    #endif
+                   // #endif
                         wait(1);
                     }
                 #endif   
-                    sprintf(sbuf, "nlst\r\n");             
+                    sprintf(sbuf, "nlst\r\n");  
+                    printf("the image is %s\n",sbuf);
+                    //count++;           
                     FTPClientControlSock->send(sbuf, strlen(sbuf));  
                 }
-            }  
+               
+            } 
+            
         }
+         //printf("count is : %d\n", count); 
         blsflag = false;
         return 1;
     }
@@ -415,15 +457,16 @@
     
     if(blogin){
     
-        sprintf(sbuf, "cwd %s\r\n", dirname);             
+        sprintf(sbuf, "cwd %s\r\n", dirname);    
+        printf("current working directory is : %s\n",dirname);         
         FTPClientControlSock->send(sbuf, strlen(sbuf));
         
         while(!bcdflag){
             size = FTPClientControlSock->receive(rbuf, sizeof(rbuf));
             if(size > 0){
-            #ifdef DEBUG
+            //#ifdef DEBUG
                 printf("Received message from server: %s\r\n", rbuf);
-            #endif
+           // #endif
                 if (!strncmp(rbuf, "250", 3)){
                     bcdflag = true;
                 }