FTPClient

Fork of FTPClient by Ricky Kwon

Revision:
4:8ecc32e7c69b
Parent:
3:4fd8e5cd6307
--- a/FTPClient.cpp	Wed Jul 29 00:03:21 2015 +0000
+++ b/FTPClient.cpp	Thu Dec 14 04:49:35 2017 +0000
@@ -3,6 +3,7 @@
 #include "FTPClient.h"
 //#define DEBUG
 FTPClient::FTPClient(PinName mosi, PinName miso, PinName sclk, PinName ssel, const char* root) : _SDFileSystem(mosi, miso, sclk, ssel, root){
+    //printf("Object");
     blogin = false;
     bopenflag = false;
     brfileflag = false;
@@ -12,8 +13,70 @@
     bmkdirflag = false;
     bcdflag = false;
     bquitflag = false;
+    //printf("Object");
 }
-bool FTPClient::open(char* ip, int port, char* id, char* pass){
+
+// made for checking
+
+
+bool FTPClient::open(char ip[], int port, char id[], char pass[]){
+    //printf("\nInside Open");
+/*
+      printf("\n%s",ip);
+      printf("\n%d",port);
+      printf("\n%s",id);
+      printf("\n%s",pass);
+      printf("\nHappens");
+      printf("\nHappens\n");
+  */
+    
+    FTPClientControlSock = new TCPSocketConnection();
+    FTPClientDataSock = new TCPSocketConnection();
+    //printf("\nHappens\n");
+    #if 0
+    do{
+        FTPClientControlSock->connect(ip, port);
+    }while(!FTPClientControlSock->is_connected());
+    #endif
+    #if 1
+    while (FTPClientControlSock->connect(ip, port) < 0) {
+    #ifdef DEBUG
+        printf("Unable to connect to (%s) on port (%d)\r\n", ip, port);
+    #endif
+        wait(1);
+    }
+    #endif
+    
+    while(!blogin){
+        size = FTPClientControlSock->receive(rbuf, sizeof(rbuf));
+        if(size > 0){
+        #ifdef DEBUG
+            printf("Received message from server: %s\r\n", rbuf);
+        #endif
+            if (!strncmp(rbuf, "220", 3)){
+                printf("%s\r\n", rbuf);
+                sprintf(sbuf, "user %s\r\n", id);             
+                FTPClientControlSock->send(sbuf, strlen(sbuf));
+            }
+            else if (!strncmp(rbuf, "331", 3)){
+                sprintf(sbuf, "pass %s\r\n", pass);             
+                FTPClientControlSock->send(sbuf, strlen(sbuf));
+            }
+            else if (!strncmp(rbuf, "230", 3)){
+                blogin = true;
+            }
+            else{
+                blogin = true;
+            }
+        }  
+    }
+    return 1;
+}
+//*/
+/*
+bool FTPClient::open(char* ip, int port, char* id, char* pass)
+{    
+    printf("Inside Open");
     
     FTPClientControlSock = new TCPSocketConnection;
     FTPClientDataSock = new TCPSocketConnection;
@@ -57,7 +120,7 @@
     }
     return 1;
 }
-
+*/
 bool FTPClient::getfile(char* myfilename, char* filename){
     
     if(blogin){