私は2日以上頭を掻いていますが、それでもやっぱり次のようにすることはできません! ftp://ftp.ncbi.nlm.nih.govにあるGeoデータセットをすべてダウンロードして、各データセットに興味のあるキーワードが含まれているかどうかを確認する必要があります。手動でデータセットをダウンロードしてファイルを確認できました希望のキーワードを入力します。しかし、データセットの数が膨大なので、私は手動で行うことはできません。私はそれを行うためのプログラムを書いておきたい。最初のステップでは、ダウンロードできるかどうかを試したところです。次のように 構造は次のとおりです。ディレクトリのようなツリーに存在するリモートGZファイルをダウンロードすると、くすぐりはしません
hots->
/geo/
-> datasets/
-> GDS1nnn/ .... all the way through GDS6nnn and each of them
contain more than 600 directories; ordered by number i.e.
GDS1001. Now, in each of these directories:
---> soft inside this folder there are 2 files that are named
like this: folder name (GDS1001)+_full.soft.gz
これは私がダウンロードして、私が探していますキーワードは、そのファイル内にあるかどうかを確認する必要があると思うのファイルです。
は、ここに私のコードです:
ftp = FTP('ftp.ncbi.nlm.nih.gov') # remember that you ONLY need to provide the host name not the complete address!
ftp.login()
#ftp.retrlines('LIST')
ftp.cwd("/geo/datasets/GDS1nnn/")
ftp.retrlines('LIST')
filenames = ftp.nlst()
count = len(filenames)
curr = 0
print ("found {} files".format(count))
for filename in filenames:
first_path=filename+"/soft/"
second_path=first_path+filename+"_full.soft.gz"
#print(second_path)
local_filename = os.path.join(r'full path to a folder that I
created')
file = open(local_filename, 'wb')
ftp.retrbinary('RETR ' + second_path, file.write)
file.close()
ftp.quit()
出力:
file = open(local_filename, 'wb')
PermissionError: [Errno 13] Permission denied: full path to a folder that I created'
しかし、私はこのフォルダの読み取りと書き込みの両方の権限を持っています。 ご協力ありがとうございます
なぜファイル名に 'for filename:'ループが2つあるのですか?最初のものは全て 'first_path'と' second_path'に値を代入しています。 2番目の 'for'ループは、最初のループで' second_path'に割り当てられた** last **値を使用することにも注意してください。これが権限の問題と関係があるかどうかは不明ですが、明らかに間違っています。 – martineau