Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FTP download directories
#10
Not all sites work with pysftp.

Can write something with ftplib.
from ftplib import FTP
import os

ftp = FTP('ftp.debian.org')
ftp.login()
ftp.cwd('debian')
ftp.cwd('doc')
# get filenames within the directory
filenames = ftp.nlst()
print(filenames)

# download the files
for file in filenames:
   if '.txt' in file:
       file_name = os.path.join(r"E:/div", file)
       lf = open(file_name, "wb")
       ftp.retrbinary("RETR " + file, lf.write)
lf.close()
Work almost there problem with 1 file in directory that stall download.
So can write some different.
All files okay,not recursive for sub-folders that can be a fine traning task to write.
from bs4 import BeautifulSoup
import requests
from urllib.request import urlretrieve

url = 'http://ftp.debian.org/debian/doc/'
url_get = requests.get(url)
soup = BeautifulSoup(url_get.content, 'lxml')
data = soup.find_all('a')
for name in data:
    if 'txt' in name.get('href'):
        urlretrieve(url+name.get('href'), name.get('href'))
Reply


Messages In This Thread
FTP download directories - by Sorkkaelain - Mar-14-2017, 09:35 PM
RE: FTP download directories - by Larz60+ - Mar-15-2017, 12:03 AM
RE: FTP download directories - by wavic - Mar-15-2017, 03:28 AM
RE: FTP download directories - by Larz60+ - Mar-15-2017, 05:57 AM
RE: FTP download directories - by Sorkkaelain - Mar-15-2017, 12:54 PM
RE: FTP download directories - by wavic - Mar-15-2017, 01:08 PM
RE: FTP download directories - by Sorkkaelain - Mar-15-2017, 02:40 PM
RE: FTP download directories - by wavic - Mar-15-2017, 03:54 PM
RE: FTP download directories - by Sorkkaelain - Mar-15-2017, 05:06 PM
RE: FTP download directories - by snippsat - Mar-15-2017, 09:24 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020