0
ダウンロードはPythonで動作しませんか?pythonスクリプトを使用してFTPロケーションからディレクトリ/ファイルをダウンロード
私は単純なpythonプログラムを書いてFTPの場所からファイルを取得しましたが、実行するとエラー[Errno 13] Permission deniedメッセージが表示されます。
私のコードは以下の通りです。なぜそれが機能していないのか?
import ftplib
from ftplib import FTP, error_perm
def getFTPDir(dirpath):
f = ftplib.FTP(ip, username, password)
try:
f.cwd(dirpath)
nameList = f.nlst()
oldest = nameList[0]
newest = nameList[-1]
newest = oldest
newDirPath = dirpath +'/'+ newest
print f.cwd(newDirPath)
subNameList = f.nlst()
for i in range (len(subNameList)):
f.cwd(newDirPath + '/' + str(subNameList[i]))
nameList1 = f.nlst()
filename = nameList1[i]
print "downloading..............", filename
f.retrbinary('RETR '+ filename, open(os.path.join(destination,localPath),"wb").write)
print filename + " downloaded"
try:
fhandle = open(filename, 'wb')
f.retrbinary('RETR ' + filename, fhandle.write)
except Exception, e:
print str(e)
finally:
fhandle.close()
except error_perm:
return
except Exception, e:
print str(e)
finally:
f.close()
エラーが発生した行かに言ってください...あなたが書いてみるところ
こうすることで、あなたが見ることができます:UTはあなたが次の行に書いたものをやって続ける、あるいはさらに良いと使用します... –
f.retrbinary( 'RETR' + filename、open(os.path.join(destination、localPath)、 "wb"))write) – Dush