-3
import ftplib
ftp = ftplib.FTP()

ftp.cwd('ftp://ftp.cdc.noaa.gov/Datasets/cpc_global_precip/')

*** AttributeError: 'NoneType' object has no attribute 'sendall'

Any reason why I am getting the error message above? I can access the FTP site through a browser just ok

user308827
  • 21,227
  • 87
  • 254
  • 417

1 Answers1

3

You code tries to create an unconnected FTP instance and then change in this unconnected instance to a directory called ftp://ftp.cdc.noaa.gov/Datasets/cpc_global_precip/. There are several things wrong with it: first you need to connect to the server, then you need to login (anonymous login in this case) and then you can change to the real directory instead of some URL used as directory name:

import ftplib
ftp = ftplib.FTP('ftp.cdc.noaa.gov')
ftp.login('ftp','user@example.com')
ftp.cwd('/Datasets/cpc_global_precip/')
print(ftp.retrlines('LIST'))
Steffen Ullrich
  • 114,247
  • 10
  • 131
  • 172