1

I am trying to download all the files present in a directory using a simple python code, I used the ftplib but I am unable to get proper results.

from ftplib import FTP
import os
folder='D:\\New folder'
os.chdir(folder)
ftp = FTP('http://mtb.dobzhanskycenter.org/VCF/')
ftp.login()
vcffiles = ftp.nlst()
for files in vcffiles:
    local_filename = os.path.join('D:\\New folder', files)
    file = open(local_filename, 'wb')
    ftp.retrbinary('RETR '+ files, file.write)
    file.close()
ftp.quit()

Error:-

Traceback (most recent call last):
  File "D:/Python Class/url.py", line 5, in <module>
    ftp = FTP('http://mtb.dobzhanskycenter.org/VCF/')
  File "C:\Program Files\Python37\lib\ftplib.py", line 117, in __init__
    self.connect(host)
  File "C:\Program Files\Python37\lib\ftplib.py", line 152, in connect
    source_address=self.source_address)
  File "C:\Program Files\Python37\lib\socket.py", line 707, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "C:\Program Files\Python37\lib\socket.py", line 748, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
  socket.gaierror: [Errno 11001] getaddrinfo failed
Paolo Mossini
  • 1,064
  • 2
  • 15
  • 23

1 Answers1

0

The first argument of FTP constructor is host – a hostname or an IP address – not an URL (let alone HTTP URL – It's FTP client, not HTTP client).

So it should be:

ftp = FTP('mtb.dobzhanskycenter.org')

If you want o list files in /VCF subfolder, either do:

ftp.cwd('VCF')      
vcffiles = ftp.nlst()

or

vcffiles = ftp.nlst('VCF')
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992