以太网盾arduino上的FTP客户端

时间:2016-10-31 16:08:23

标签: ftp arduino server client

我想做一个项目,其中数据保存在SD卡上,然后使用以太网屏蔽,这些数据使用FTP客户端arduino发送到ftp服务器。服务器我有免费托管。

这是来自ftptest的数据服务器:

 

    Status: Resolving address of cba.pl
    Status: Connecting to 95.211.144.68
    Warning: The entered address does not resolve to an IPv6 address.
    Status: Connected, waiting for welcome message...
    Reply: 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
    Reply: 220-You are user number 57 of 200 allowed.
    Reply: 220-Local time is now 16:30. Server port: 21.
    Reply: 220-This is a private system - No anonymous login
    Reply: 220-IPv6 connections are also welcome on this server.
    Reply: 220 You will be disconnected after 5 minutes of inactivity.
    Command: CLNT https://ftptest.net on behalf of 2a02:a311:c020:3200:c10d:18e1:36a5:8e2
    Reply: 530 You aren't logged in
    Command: AUTH TLS
    Reply: 234 AUTH TLS OK.
    Status: Performing TLS handshake...
    Status: TLS handshake successful, verifying certificate...
    Status: Received 2 certificates from server.
    Status: cert[0]: subject='CN=www.cba.pl' issuer='C=US,O=Let\27s Encrypt,CN=Let\27s Encrypt Authority X3'
    Status: cert[1]: subject='C=US,O=Let\27s Encrypt,CN=Let\27s Encrypt Authority X3' issuer='O=Digital Signature Trust Co.,CN=DST Root CA X3'
    Command: USER wsalkowski
    Reply: 331 User wsalkowski OK. Password required
    Command: PASS ********
    Reply: 230-Your bandwidth usage is restricted
    Reply: 230-OK. Current restricted directory is /
    Reply: 230 Max allowed filesize is 10485760 bytes
    Command: SYST
    Reply: 215 UNIX Type: L8
    Command: FEAT
    Reply: 211-Extensions supported:
    Reply: EPRT
    Reply: IDLE
    Reply: MDTM
    Reply: SIZE
    Reply: MFMT
    Reply: REST STREAM
    Reply: MLST type*;size*;sizd*;modify*;UNIX.mode*;UNIX.uid*;UNIX.gid*;unique*;
    Reply: MLSD
    Reply: AUTH TLS
    Reply: PBSZ
    Reply: PROT
    Reply: UTF8
    Reply: TVFS
    Reply: ESTA
    Reply: PASV
    Reply: EPSV
    Reply: SPSV
    Reply: ESTP
    Reply: 211 End.
    Command: PBSZ 0
    Reply: 200 PBSZ=0
    Command: PROT P
    Reply: 200 Data protection level set to "private"
    Command: PWD
    Reply: 257 "/" is your current location
    Status: Current path is /
    Command: TYPE I
    Reply: 200 TYPE is now 8-bit binary
    Command: PASV
    Reply: 227 Entering Passive Mode (95,211,144,68,218,36)
    Command: MLSD
    Status: Data connection established, performing TLS handshake...
    Reply: 150 Accepted data connection
    Status: TLS handshake successful, verifying certificate...
    Status: Received 2 certificates from server.
    Status: cert[0]: subject='CN=www.cba.pl' issuer='C=US,O=Let\27s Encrypt,CN=Let\27s Encrypt Authority X3'
    Status: cert[1]: subject='C=US,O=Let\27s Encrypt,CN=Let\27s Encrypt Authority X3' issuer='O=Digital Signature Trust Co.,CN=DST Root CA X3'
    Status: TLS session of transfer connection has been resumed.
    Listing: type=cdir;sizd=4096;modify=20160501192730;UNIX.mode=0755;UNIX.uid=0;UNIX.gid=0;unique=803g16f353ca; .
    Listing: type=pdir;sizd=4096;modify=20160501192730;UNIX.mode=0755;UNIX.uid=0;UNIX.gid=0;unique=803g16f353ca; ..
    Listing: type=dir;sizd=4096;modify=20161031125022;UNIX.mode=0700;UNIX.uid=1098695;UNIX.gid=33;unique=803g2259f68; wsalkowski.cba.pl
    Reply: 226-Options: -a -l
    Reply: 226 3 matches total
    Status: Success
    Results
    Your server is working and assorted routers/firewalls have been correctly configured for explicit FTP over TLS as performed by this test. However there have been warnings about compatibility issues, not all users will be able to use your server.
    For maximum compatibility, consider resolving these warnings. 

这里是串行监视器arduino ide的结果


    Ready. Press f or r
    kkksdsSD opened
    Command connected
    220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
    220-You are user number 52 of 200 allowed.
    220-Local time is now 15:32. Server port: 21.
    220-This is a private system - No anonymous login
    220-IPv6 connections are also welcome on this server.
    220 You will be disconnected after 5 minutes of inactivity.
    331 User wsalkowski OK. Password required
    230-Your bandwidth usage is restricted
    230-OK. Current restricted directory is /
    230 Max allowed filesize is 10485760 bytes
    215 UNIX Type: L8
    227 Entering Passive Mode (95,211,144,65,208,115)
    Data port: 53363
    Data connected
    553 Can't open that file: No such file or directory
    221-Goodbye. You uploaded 0 and downloaded 0 kbytes.
    221 Logout.
    Command disconnected
    SD closed
    FTP FAIL
    SD opened
    Command connected
    220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
    220-You are user number 53 of 200 allowed.
    220-Local time is now 15:32. Server port: 21.
    220-This is a private system - No anonymous login
    220-IPv6 connections are also welcome on this server.
    220 You will be disconnected after 5 minutes of inactivity.
    331 User wsalkowski OK. Password required
    230-Your bandwidth usage is restricted
    230-OK. Current restricted directory is /
    230 Max allowed filesize is 10485760 bytes
    215 UNIX Type: L8
    227 Entering Passive Mode (95,211,144,65,208,248)
    Data port: 53496
    Data connected
    553 Can't open that file: No such file or directory
    221-Goodbye. You uploaded 0 and downloaded 0 kbytes.
    221 Logout.
    Command disconnected
    SD closed
    FTP FAIL

这里是代码arduino(代码来自http://playground.arduino.cc/Code/FTP

/*


     FTP passive client for IDE v1.0.1 and w5100/w5200
       Posted October 2012 by SurferTim
       Modified 6 June 2015 by SurferTim
    */

    #include 
    #include 
    #include 
    // comment out next line to write to SD from FTP server
    #define FTPWRITE

    // this must be unique
    byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x59, 0x67 } ;  

    // change to your network settings
    IPAddress ip( 192, 168, 0, 25 );    
    IPAddress gateway( 192, 168, 0, 1 );
    IPAddress subnet( 255, 255, 255, 0 );

    // change to your server
    IPAddress server( 95, 211, 144, 65);

    EthernetClient client;
    EthernetClient dclient;

    char outBuf[128];
    char outCount;

    // change fileName to your file (8.3 format!)
    char fileName[13] = "POMIARY.txt";

    void setup()
    {
      Serial.begin(9600);

      digitalWrite(10,HIGH);

      if(SD.begin(4) == 0)
      {
        Serial.println(F("SD init fail"));          
      }

      Ethernet.begin(mac, ip, gateway, gateway, subnet); 
      digitalWrite(10,HIGH);
      delay(2000);
      Serial.println(F("Ready. Press f or r"));
    }

    void loop()
    {
      byte inChar;

      inChar = Serial.read();

      if(inChar == 'f')
      {
        if(doFTP()) Serial.println(F("FTP OK"));
        else Serial.println(F("FTP FAIL"));
      }

      if(inChar == 'r')
      {
        readSD();    
      }

    }

    File fh;

    byte doFTP()
    {
    #ifdef FTPWRITE
      fh = SD.open(fileName,FILE_READ);
    #else
      SD.remove(fileName);
      fh = SD.open(fileName,FILE_WRITE);
    #endif

      if(!fh)
      {
        Serial.println(F("SD open fail"));
        return 0;    
      }

    #ifndef FTPWRITE  
      if(!fh.seek(0))
      {
        Serial.println(F("Rewind fail"));
        fh.close();
        return 0;    
      }
    #endif

      Serial.println(F("SD opened"));

      if (client.connect(server,21)) {
        Serial.println(F("Command connected"));
      } 
      else {
        fh.close();
        Serial.println(F("Command connection failed"));
        return 0;
      }

      if(!eRcv()) return 0;

    // Change to your user and password  
      client.write("USER wsalkowski\r\n");

      if(!eRcv()) return 0;

      client.write("PASS pass\r\n");

      if(!eRcv()) return 0;

      client.write("SYST\r\n");

      if(!eRcv()) return 0;

      client.write("PASV\r\n");

      if(!eRcv()) return 0;


      char *tStr = strtok(outBuf,"(,");
      int array_pasv[6];
      for ( int i = 0; i  63)
        {
          dclient.write(clientBuf,64);
          clientCount = 0;
        }
      }

      if(clientCount > 0) dclient.write(clientBuf,clientCount);

    #else
      while(dclient.connected())
      {
        while(dclient.available())
        {
          char c = dclient.read();
          fh.write(c);      
          Serial.write(c); 
        }
      }
    #endif

      dclient.stop();
      Serial.println(F("Data disconnected"));

      if(!eRcv()) return 0;

      client.println(F("QUIT"));

      if(!eRcv()) return 0;

      client.stop();
      Serial.println(F("Command disconnected"));

      fh.close();
      Serial.println(F("SD closed"));
      return 1;
    }

    byte eRcv()
    {
      byte respCode;
      byte thisByte;

      while(!client.available()) delay(1);

      respCode = client.peek();

      outCount = 0;

      while(client.available())
      {  
        thisByte = client.read();    
        Serial.write(thisByte);

        if(outCount = '4')
      {
        efail();
        return 0;  
      }

      return 1;
    }


    void efail()
    {
      byte thisByte = 0;

      client.println(F("QUIT"));

      while(!client.available()) delay(1);

      while(client.available())
      {  
        thisByte = client.read();    
        Serial.write(thisByte);
      }

      client.stop();
      Serial.println(F("Command disconnected"));
      fh.close();
      Serial.println(F("SD closed"));
    }

    void readSD()
    {
      fh = SD.open(fileName,FILE_READ);

      if(!fh)
      {
        Serial.println(F("SD open fail"));
        return;    
      }

      while(fh.available())
      {
        Serial.write(fh.read());
      }

      fh.close();
    }

如果有人告诉我可以做什么以及我做错了什么?

我可以使用filezilla投放文件,但仅限于文件夹wsalkowski.cba.pl

enter image description here

问题是否无法从ftp客户端arduino访问路径/wsalkowski.cba.pl?也就是说,带有默认SD卡的文件被抛到根文件夹/,它没有权限chmod?

请帮帮我,对不起我的英文

1 个答案:

答案 0 :(得分:0)

让我们尝试更改您的FTP服务器。如果你登录你的FTP,它可能是服务器中的问题。