Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage on ESP32 / Error: Could not connect to... #2

Closed
asturkoglu opened this issue Sep 10, 2019 · 6 comments
Closed

Usage on ESP32 / Error: Could not connect to... #2

asturkoglu opened this issue Sep 10, 2019 · 6 comments
Labels

Comments

@asturkoglu
Copy link

Can I use it on ESP32 directly? I succesfully imported it on my board, but couldn't connect to FTP server.
>> ftp = FTP(host='192.168.0.14',port=21,user='esp32',passwd='1234')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "ftplib.py", line 206, in __init__
File "ftplib.py", line 264, in connect
File "ftplib.py", line 242, in _create_connection
Error: Could not connect to ('192.168.0.14', 21)
I can access to the storage via Chrome, with same settings (user, passwd, etc.)

@SpotlightKid
Copy link
Owner

You can enable debugging like this:

from ftplib import FTP

class DebugFTP(FTP):
    debugging = 1

ftp = DebugFTP(host='192.168.0.14', port=21, user='esp32', passwd='1234')

This will print the exception message when the socket connection fails and may give some clue why that is.

@asturkoglu
Copy link
Author

asturkoglu commented Sep 10, 2019

>>> ftp = DebugFTP('192.168.0.14', 21, 'esp32', '1234')
requested length 2 but object has length 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ftplib.py", line 206, in __init__
  File "ftplib.py", line 264, in connect
  File "ftplib.py", line 242, in _create_connection
Error: Could not connect to ('192.168.0.14', 21)
>>> ftp = DebugFTP('ftp://192.168.0.14', 21, 'esp32', '1234')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ftplib.py", line 206, in __init__
  File "ftplib.py", line 264, in connect
  File "ftplib.py", line 242, in _create_connection
Error: Could not connect to ('ftp://192.168.0.14', 21)

Second trial returns no debug :/

@SpotlightKid
Copy link
Owner

The second try does not use the correct syntax for the address. Only IP addresses are allowed, no URLs.

First trial gives an important clue:

requested length 2 but object has length 1

It seems that the call to _resolve_addr() in line 226 returns something unexpected. Could you insert a `print(addrinfos) before line 227 and try again and post the output here?

@asturkoglu
Copy link
Author

asturkoglu commented Sep 10, 2019

Sorry, when I couldn't understand first clue, I also wanted to try it with ftp://
I added print function, here is the output:

>>> ftp = DebugFTP(host='192.168.0.14', port=21, user='esp32', passwd='1234')
[(2, 1, 0, '192.168.0.14', ('192.168.0.14', 21))]
requested length 2 but object has length 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ftplib.py", line 206, in __init__
  File "ftplib.py", line 265, in connect
  File "ftplib.py", line 243, in _create_connection
Error: Could not connect to ('192.168.0.14', 21)

FileZilla Server works fine I guess, here is the output of my connection from Chrome:

You appear to be behind a NAT router. Please configure the passive mode settings and forward a range of ports in your router.
Warning: FTP over TLS is not enabled, users cannot securely log in.
(000007)10.09.2019 19:35:12 - (not logged in) (192.168.0.14)> Connected on port 21, sending welcome message...
(000007)10.09.2019 19:35:12 - (not logged in) (192.168.0.14)> 220-FileZilla Server 0.9.60 beta
(000007)10.09.2019 19:35:12 - (not logged in) (192.168.0.14)> 220-written by Tim Kosse (tim.kosse@filezilla-project.org)
(000007)10.09.2019 19:35:12 - (not logged in) (192.168.0.14)> 220 Please visit https://filezilla-project.org/
(000007)10.09.2019 19:35:12 - (not logged in) (192.168.0.14)> USER anonymous
(000007)10.09.2019 19:35:12 - (not logged in) (192.168.0.14)> 331 Password required for anonymous
(000007)10.09.2019 19:35:12 - (not logged in) (192.168.0.14)> PASS ******************
(000007)10.09.2019 19:35:12 - (not logged in) (192.168.0.14)> 530 Login or password incorrect!
(000007)10.09.2019 19:35:12 - (not logged in) (192.168.0.14)> QUIT
(000007)10.09.2019 19:35:12 - (not logged in) (192.168.0.14)> 221 Goodbye
(000007)10.09.2019 19:35:12 - (not logged in) (192.168.0.14)> disconnected.
(000008)10.09.2019 19:35:34 - (not logged in) (192.168.0.14)> Connected on port 21, sending welcome message...
(000008)10.09.2019 19:35:34 - (not logged in) (192.168.0.14)> 220-FileZilla Server 0.9.60 beta
(000008)10.09.2019 19:35:34 - (not logged in) (192.168.0.14)> 220-written by Tim Kosse (tim.kosse@filezilla-project.org)
(000008)10.09.2019 19:35:34 - (not logged in) (192.168.0.14)> 220 Please visit https://filezilla-project.org/
(000008)10.09.2019 19:35:34 - (not logged in) (192.168.0.14)> USER esp32
(000008)10.09.2019 19:35:34 - (not logged in) (192.168.0.14)> 331 Password required for esp32
(000008)10.09.2019 19:35:34 - (not logged in) (192.168.0.14)> PASS ****
(000008)10.09.2019 19:35:34 - esp32 (192.168.0.14)> 230 Logged on
(000008)10.09.2019 19:35:34 - esp32 (192.168.0.14)> SYST
(000008)10.09.2019 19:35:34 - esp32 (192.168.0.14)> 215 UNIX emulated by FileZilla
(000008)10.09.2019 19:35:34 - esp32 (192.168.0.14)> PWD
(000008)10.09.2019 19:35:34 - esp32 (192.168.0.14)> 257 "/" is current directory.
(000008)10.09.2019 19:35:34 - esp32 (192.168.0.14)> TYPE I
(000008)10.09.2019 19:35:34 - esp32 (192.168.0.14)> 200 Type set to I
(000008)10.09.2019 19:35:34 - esp32 (192.168.0.14)> SIZE /
(000008)10.09.2019 19:35:34 - esp32 (192.168.0.14)> 550 File not found
(000008)10.09.2019 19:35:34 - esp32 (192.168.0.14)> CWD /
(000008)10.09.2019 19:35:34 - esp32 (192.168.0.14)> 250 CWD successful. "/" is current directory.
(000008)10.09.2019 19:35:34 - esp32 (192.168.0.14)> PASV
(000008)10.09.2019 19:35:34 - esp32 (192.168.0.14)> 227 Entering Passive Mode (192,168,0,14,199,89)
(000008)10.09.2019 19:35:34 - esp32 (192.168.0.14)> LIST -l
(000008)10.09.2019 19:35:34 - esp32 (192.168.0.14)> 150 Opening data channel for directory listing of "/"
(000008)10.09.2019 19:35:34 - esp32 (192.168.0.14)> 226 Successfully transferred "/"
(000008)10.09.2019 19:35:34 - esp32 (192.168.0.14)> QUIT
(000008)10.09.2019 19:35:34 - esp32 (192.168.0.14)> 221 Goodbye
(000008)10.09.2019 19:35:34 - esp32 (192.168.0.14)> disconnected.

Edit2: I guess my I have also port forwarding issue, I'm not sure it is related with this. I couldn't connect to my server from another computer in same network. Port forwarding is active but idk. If these two problem are connected, let me know.

@SpotlightKid
Copy link
Owner

Hmm, not sure why the socket.connect) call fails. Are you sure the network is set up correctly on your ESP32 and that address is reachable?

You might also try the ftplib.py version for the esp8266 in the sub-directory with the same name, which has a slightly different wrapper for the socket class.

@SpotlightKid
Copy link
Owner

No further feedback. Assuming improper network configuration. Feel free to re-open, if you have further information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants