nopnop2002 / esp-idf-ftpClient

ftp client for esp-idf
46 stars 7 forks source link

Unable to send to ftp server #9

Closed gr8rithic closed 9 months ago

gr8rithic commented 9 months ago

Hi, I am working with your library in esp32 dev module. The problem I am facing is I am unable to send a .log file through my esp32 but I am able to send it using filezilla software with the same file format. The problem is happening in this line ftpClient->ftpClientPut(). Can you help out will be helpful.

PS: I am able to send my data to node red ftp server but I am unable to send the data to another FTP server setup using the python script provided in this repo.

Node red package - https://flows.nodered.org/node/node-red-contrib-ftp-server

nopnop2002 commented 9 months ago

I am unable to send the data to another FTP server setup using the python script provided in this repo.

What is another FTP server setup?

I would like to clarify the issue.

From ESP32 to Node red ftp server: OK/NG?

From ESP32 to Python ftp server provided in this repo: OK/NG?

gr8rithic commented 9 months ago

I am using this code to create a FTP server

import pyftpdlib.authorizers import pyftpdlib.handlers import pyftpdlib.servers import argparse import logging import os

from pyftpdlib.handlers import FTPHandler

class Handler(FTPHandler): def on_file_sent(self, file): logging.info("send file! {}".format(file)) self.ftp_send(file)

def on_file_received(self, file):
    logging.info("received file! {}".format(file))
    self.ftp_store(file)

logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO) parser = argparse.ArgumentParser() parser.add_argument('--user', default="ftpuser", help='ftp user name. default is user') parser.add_argument('--password', default="devmode", help='ftp user password. default is password') parser.add_argument('--port', default=2121, type=int, help='ftp port. default is 2121') parser.add_argument('--timeout', type=int, default=300, help='timeout for network operations in seconds. default is 300') parser.add_argument('--passive_ports', default='30000-30009', help='range of passive ports. default is 30000-30009') parser.add_argument('--keep_alive', type=int, default=60, help='keep-alive interval in seconds. default is 60') parser.add_argument('--passive_timeout', type=int, default=300, help='passive connection timeout in seconds. default is 300') args = parser.parse_args() logging.info("user={} {}".format(type(args.user), args.user)) logging.info("password={} {}".format(type(args.password), args.password)) logging.info("port={} {}".format(type(args.port), args.port))

authorizer = pyftpdlib.authorizers.DummyAuthorizer() authorizer.add_user(args.user, args.password, os.getcwd(), perm='elradfmw') handler = Handler handler.authorizer = authorizer handler.passive_ports = range(*map(int, args.passive_ports.split('-'))) # Set passive ports range handler.timeout = args.passive_timeout # Set passive timeout

server = pyftpdlib.servers.FTPServer(("0.0.0.0", args.port), handler) server.timeout = args.timeout # Set timeout server.keep_alive_timeout = args.keep_alive # Set keep-alive interval server.serve_forever()

gr8rithic commented 9 months ago

The file I am trying to send is a log file which is stored in esp's spiffs storage

I am able to send data using filezilla but I am unable to send it using esp32 using this repo

nopnop2002 commented 9 months ago

Your python code have a bug.

class Handler(FTPHandler):
    def on_file_sent(self, file):
        logging.info("send file! {}".format(file))
        #self.ftp_send(file)

    def on_file_received(self, file):
        logging.info("received file! {}".format(file))
        #self.ftp_store(file)
    def on_file_sent(self, file):
        # do something when a file has been sent
        pass

    def on_file_received(self, file):
        # do something when a file has been received
        pass
gr8rithic commented 9 months ago

It is still not working

I am able to connect and login to the ftp server but unable to send the data file

nopnop2002 commented 9 months ago

You have too little information. This is my logging. Please tell me what's different.

$ python3 ./ftp-server.py
INFO:user=<class 'str'> ftpuser
INFO:password=<class 'str'> devmode
INFO:port=<class 'int'> 2121
INFO:concurrency model: async
INFO:masquerade (NAT) address: None
INFO:passive ports: 30000->30008
INFO:>>> starting FTP server on 0.0.0.0:2121, pid=58816 <<<
INFO:192.168.10.110:56371-[] FTP session opened (connect)
INFO:192.168.10.110:56371-[ftpuser] USER 'ftpuser' logged in.
INFO:192.168.10.110:56371-[ftpuser] STOR /home/nop/test/hello.txt completed=1 bytes=14 seconds=0.016
INFO:received file! /home/nop/test/hello.txt
INFO:192.168.10.110:56371-[ftpuser] RETR /home/nop/test/hello.txt completed=1 bytes=14 seconds=0.001
INFO:send file! /home/nop/test/hello.txt
INFO:192.168.10.110:56371-[ftpuser] FTP session closed (disconnect).
I (6563) FTP: ftp server:192.168.10.46
I (6573) FTP: ftp user  :ftpuser
I (6603) FTP: connect=1
I (6613) FTP: login=1
I (6703) FTP: -rw-rw-r--   1 nop      nop          2038 Feb 08 21:40 :
I (6713) FTP: -rw-rw-r--   1 nop      nop            83 Jun 30  2022 CMakeLists.txt
I (6713) FTP: -rw-rw-r--   1 nop      nop           984 Dec 18 07:13 a.c
I (6723) FTP: -rwxrwxr-x   1 nop      nop         16872 Dec 22 02:43 a.out
I (6733) FTP: -rw-rw-r--   1 nop      nop            33 Feb 13  2021 a.txt
I (6733) FTP: -rw-rw-r--   1 nop      nop           756 Dec 17 08:52 a2.c
I (6743) FTP: -rw-rw-r--   1 nop      nop           720 Dec 22 02:43 b.c
I (6753) FTP: -rw-rw-r--   1 nop      nop            33 Feb 13  2021 b.txt
I (6763) FTP: -rw-rw-r--   1 nop      nop         12749 Nov 22  2021 doa.py
I (6763) FTP: -rw-rw-r--   1 nop      nop          7131 Nov 23  2021 doa2.py
I (6773) FTP: -rw-rw-r--   1 nop      nop          2038 Feb 08 21:40 ftp-server.py
I (6783) FTP: -rw-rw-r--   1 nop      nop         74636 Nov 23  2021 graph.png
I (6793) FTP: -rw-rw-r--   1 nop      nop          2041 Nov 23  2021 graph.py
I (6793) FTP: -rw-rw-r--   1 nop      nop            13 Feb 09 10:03 hello.txt
I (6803) FTP: -rw-rw-r--   1 nop      nop           703 Mar 13  2021 http_client.py
I (6813) FTP: -rw-r--r--   1 nop      nop           115 May 12  2022 lib.c
I (6823) FTP: -rw-r--r--   1 nop      nop           111 May 12  2022 lib.h
I (6833) FTP: -rw-r--r--   1 nop      nop           130 May 12  2022 sub.c
I (6833) FTP: -rw-rw-r--   1 nop      nop           240 Mar 26  2023 tcp-client.py
I (6843) FTP: -rw-rw-r--   1 nop      nop           549 Mar 29  2023 tcp-server.py
I (6853) FTP: -rw-rw-r--   1 nop      nop          1723 Mar 09  2021 test.c
I (6863) FTP: -rw-rw-r--   1 nop      nop           286 Jan 29 13:26 test.py
I (6873) FTP: -rw-rw-r--   1 nop      nop           563 Feb 11  2023 udp-receive.py
I (6873) FTP: -rw-rw-r--   1 nop      nop           284 Mar 26  2023 udp-recv.py
I (6883) FTP: -rw-rw-r--   1 nop      nop           262 Mar 28  2023 udp-send.py
I (6953) FTP:
I (6983) FTP: Wrote the text on /root/hello.txt
I (7033) FTP: ftpClientPut /root/hello.txt ---> hello.txt
I (7033) FTP: Deleted /root/hello.txt
I (7113) FTP: ftpClientGet /root/hello.txt <--- hello.txt
I (7113) FTP: Open /root/hello.txt
I (7113) FTP: Read from /root/hello.txt: 'Hello World!'
I (7133) FTP: SPIFFS unmounted
I (7133) main_task: Returned from app_main()

Please try the project I have provided first.

Please contact me if it doesn't work with the project I provided.

If your project is not working properly, there is a problem with your project.

You need to solve it yourself.

gr8rithic commented 9 months ago

I will check and will let you know I have converted the espidf code to arduino-esp32 (v 2.0.14)will try uploading using espidf and let you know I have attached my logging

BTW - is there any limit on the size of data? image

nopnop2002 commented 9 months ago

How did you get this logging? Could you please elaborate on what you did to get this logging?

I don't understand your problem at all.

If there is a problem with my code, please point out the exact problem in the code.

I have converted the espidf code to arduino-esp32

This project is guaranteed to work with ESP-IDF. Operation with Arduino environment is not guaranteed.

I'll say again.

Please try the project I have provided first.

Please contact me if it doesn't work with the project I provided.

If your project is not working properly, there is a problem with your project.

You need to solve it yourself.

is there any limit on the size of data?

I don't think there are any restrictions.