Python 2.5 script to connect to FTP and download file

前端 未结 3 2056
死守一世寂寞
死守一世寂寞 2020-12-18 16:00

I am sure this has been resolved before but I cannot seem to find a similar Q&A (newbie) Using Windows XP and Python 2.5, I m trying to use a script to connect to an FTP

相关标签:
3条回答
  • 2020-12-18 16:21

    I can't understand which library are you using. Python standard urllib2 is sufficient:

    import urllib2, shutil
    
    ftpfile = urllib2.urlopen("ftp://host.example.com/path/to/file")
    localfile = open("/tmp/downloaded", "wb")
    shutil.copyfileobj(ftpfile, localfile)
    

    If you need to login (anonymous login isn't sufficient), then specify the credentials inside the url:

    urllib2.urlopen("ftp://user:password@host.example.com/rest/of/the/url")
    
    0 讨论(0)
  • 2020-12-18 16:26
    ftp.login('USERNAME', 'password') 
    

    Replace this with real data. According to the error you are trying to login as "USERNAME" with the password "password" which obviously won't work.

    Also, replace servername in ftp = FTP('servername') with the hostname of the server you want to connect to.

    0 讨论(0)
  • 2020-12-18 16:39

    the first trivial check would be to open an interactive session (i.e. ftp yourself to this server with the same credentials), to be sure that this is not a permission issue..

    Another source of failure, you might need to give your username as domain\username when connecting to a MS ftp server.

    Maybe that helps ?

    0 讨论(0)
提交回复
热议问题