RetroCode
RetroCode

Reputation: 332

Python equivalent of this Curl command

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

curl  ftp://username:[email protected] \
    --retry 999 \
    --retry-max-time 0
    -o 'target.txt' -C -

How would this look in python ?

Things I have looked into:

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

Upvotes: 0

Views: 956

Answers (2)

be_good_do_good
be_good_do_good

Reputation: 4441

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.

Upvotes: 1

girish946
girish946

Reputation: 745

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()

Upvotes: 0

Related Questions