0

I am trying to download a file using python, imitating the same behavior as this curl command:

curl  ftp://username:password@example.com \
    --retry 999 \
    --retry-max-time 0
    -o 'target.txt' -C -

How would this look in python ?

Things I have looked into:

  • Requests : no ftp support

  • Python-wget: no download resume support

  • requests-ftp : no download resume support

  • fileDownloader : broken(?)

I am guessing one would need to build this from scratch and go low level with pycurl or urllib2 or something similar.

I am trying to create this script in python and I feel lost.. Should I just call curl from python subprocess ?

Any point to the write direction would be much appreciated

RetroCode
  • 342
  • 5
  • 14

2 Answers2

1

you can use python's inbuilt ftplib

Here is the code:

from ftplib import FTP

ftp = FTP('example.com', 'username', 'password') #logs in

ftp.retrlines() # to see the list of files and directories ftp.cwd('to change to any directory')

ftp.retrbinary('RETR filename', open('Desktop\filename', 'wb').write) # start downloading

ftp.close() # close the connection

Auto resume is supported. I even tried turning off my wifi and checked if the download is resuming.

You can refer to /Python27/Lib/ftplib.py for default GLOBAL_TIME_OUT settings.

be_good_do_good
  • 4,311
  • 3
  • 28
  • 42
0

there is this library for downloading files from ftp server

fileDownloader.py

to download the file

downloader = fileDownloader.DownloadFile(‘http://example.com/file.zip’, “C:UsersusernameDownloadsnewfilename.zip”, (‘username’,’password’)) 

downloader.download()

to resume download

downloader = fileDownloader.DownloadFile(‘http://example.com/file.zip’, “C:UsersusernameDownloadsnewfilename.zip”, (‘username’,’password’)) 

downloader.resume()
girish946
  • 745
  • 9
  • 24
  • I have checked this library but it seems to be broken. Namely when I try "import fileDownloader" or "import filedownloader" module cannot be found. Did you try it ? – RetroCode Aug 26 '16 at 19:57
  • not recently I tried it a while ago. at that time it did work fine. – girish946 Aug 26 '16 at 20:00
  • do you remember what version you tried ? Or how you imported the file ? – RetroCode Aug 26 '16 at 20:01
  • I am afraid that doesn't solve my problem either "As you can see, I'm not been able to detect the timeout and retry the connection, but when i got timeout, I simply reconnect again" – RetroCode Aug 26 '16 at 20:02