How can I connect to a FTP server in Python?

Viewed 264

I am having problems when I try to connect to a ftp server, I am using a Mac with BigSur and Python3.

Here is my code:

import ftplib

FTP_HOST = "ftp://myserver"
FTP_USER = "user"
FTP_PASS = "pass"

# connect to the FTP server
ftp = ftplib.FTP(FTP_HOST, FTP_USER, FTP_PASS)

Here what it returns:


Traceback (most recent call last):
  File "/Users/adrianrodriguezgalisteo/jonsuGo/test_upload.py", line 8, in <module>
    ftp = ftplib.FTP(FTP_HOST, FTP_USER, FTP_PASS)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ftplib.py", line 119, in __init__
    self.connect(host)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ftplib.py", line 156, in connect
    self.sock = socket.create_connection((self.host, self.port), self.timeout,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socket.py", line 822, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socket.py", line 953, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known

I just want to connect to the server and upload a file.

Thank you.

1 Answers
Related