0

I've noticed that the FTP library doesn't seem to have a method or function of straight up downloading a file from an FTP server. The only function I've come across for downloading a file is ftp.retrbinary and in order to transfer the file contents, you essentially have to write the contents to a pre-existing file on the local computer where the Python script is located.

Is there a way to download the file as-is without having to create a local file first?

Edit: I think the better question to ask is: do I need to have a pre-existing file in order to download an FTP server file's contents?

BestPractices
  • 12,481
  • 28
  • 93
  • 139
simplycoding
  • 2,488
  • 8
  • 39
  • 74

1 Answers1

0

To download a file from FTP this code will do the job

import urllib urllib.urlretrieve('ftp://server/path/to/file', 'file') # if you need to pass credentials: # urllib.urlretrieve('ftp://username:password@server/path/to/file', 'file')

Ayyoub
  • 3,055
  • 1
  • 17
  • 32