久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

用于連接 FTP 并下載文件的 Python 2.5 腳本

Python 2.5 script to connect to FTP and download file(用于連接 FTP 并下載文件的 Python 2.5 腳本)
本文介紹了用于連接 FTP 并下載文件的 Python 2.5 腳本的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我確信這已經(jīng)解決了,但我似乎找不到類似的問答(新手)使用 Windows XP 和 Python 2.5,我正在嘗試使用腳本連接到 FTP 服務器并下載文件.它應該很簡單,但是按照類似腳本的說明,我得到了錯誤:

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 server and dowload files. It should be simple but following the instructions of similar scripts I get the errors:

ftp.login('USERNAME')
  File "C:Python25libftplib.py", line 373, in login
    if resp[0] == '3': resp = self.sendcmd('PASS ' + passwd)
  File "C:Python25libftplib.py", line 241, in sendcmd
    return self.getresp()
  File "C:Python25libftplib.py", line 216, in getresp
    raise error_perm, resp
error_perm: 530 User USERNAME cannot log in.

我使用的腳本是:

def handleDownload(block):
    file.write(block)
    print ".",

# Create an instance of the FTP object
# FTP('hostname', 'username', 'password')
ftp = FTP('servername')

print 'ftplib example'
# Log in to the server
print 'Logging in.'
# You can specify username and password here if you like:
ftp.login('USERNAME', 'password') 
#print ftp.login()

# This is the directory 
directory = '/GIS/test/data'
# Change to that directory.  
print 'Changing to ' + directory
ftp.cwd(directory)

# Print the contents of the directory
ftp.retrlines('LIST')

我很欣賞這可能是一個微不足道的問題,但如果有人能提供一些見解,那將非常有幫助!

I appreciate this might be a trivial question, but if anyone can provide some insights it would be very helpful!

謝謝,S

推薦答案

我不明白你用的是哪個庫.Python 標準 urllib2 就足夠了:

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)

如果您需要登錄(匿名 登錄是不夠的),請在 url 中指定憑據(jù):

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

這篇關于用于連接 FTP 并下載文件的 Python 2.5 腳本的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

Why I cannot make an insert to Python list?(為什么我不能插入 Python 列表?)
Insert a column at the beginning (leftmost end) of a DataFrame(在 DataFrame 的開頭(最左端)插入一列)
Python psycopg2 not inserting into postgresql table(Python psycopg2 沒有插入到 postgresql 表中)
list extend() to index, inserting list elements not only to the end(list extend() 索引,不僅將列表元素插入到末尾)
How to add element in Python to the end of list using list.insert?(如何使用 list.insert 將 Python 中的元素添加到列表末尾?)
TypeError: #39;float#39; object is not subscriptable(TypeError:“浮動對象不可下標)
主站蜘蛛池模板: 狠狠操狠狠色 | 欧美激情一区二区 | 亚洲视频免费 | 国产一区亚洲 | 亚洲不卡视频 | 日韩欧美一区二区三区在线播放 | 国产精品伦一区二区三级视频 | 精品久| 九一视频在线观看 | 久久精品一区 | 国产一区二区三区四区区 | 香蕉一区 | 一区二区视频免费观看 | www亚洲一区| 美女黄频| 爱爱无遮挡 | 国产精品三级 | 日韩久久久久久 | 精品一区二区三区四区五区 | 欧美一级免费 | 欧美精品成人一区二区三区四区 | 91传媒在线播放 | 亚洲一区二区免费视频 | 亚洲成人中文字幕 | 欧美第一页 | 五月激情综合网 | 日韩av大片免费看 | 蜜桃视频在线观看免费视频网站www | 久久精品日产第一区二区三区 | 午夜极品 | 操亚洲| 亚洲国产中文字幕 | 黄色网址免费在线观看 | 成人在线网 | 国产精品免费观看视频 | 国产精品一区在线观看 | 日韩国产在线 | 日韩在线电影 | 成人免费视频网 | 精品欧美一区二区三区久久久 | 中文字幕不卡一区 |