-
Notifications
You must be signed in to change notification settings - Fork 62
Open
Description
I am trying to implement a the advanced-download-and-upload-abort-restart example for my use and seem to have come across an infinte loop when my first file completes the download:
import asyncio
import aioftp
import os
import pathlib
import aiofiles
import logging
import pathlib
import aiofiles.os as aos
import async_timeout
async def list_files(model, var, dest_dir):
pr_paths = [pathlib.PurePosixPath('/pub/dcp/archive/cmip5/loca/LOCA_2016-04-02/ACCESS1-0/16th/historical/r1i1p1/pr/pr_day_ACCESS1-0_historical_r1i1p1_19500101-19501231.LOCA_2016-04-02.16th.nc'),
pathlib.PurePosixPath('/pub/dcp/archive/cmip5/loca/LOCA_2016-04-02/ACCESS1-0/16th/historical/r1i1p1/pr/pr_day_ACCESS1-0_historical_r1i1p1_19510101-19511231.LOCA_2016-04-02.16th.nc')]
for path in pr_paths:
dest = dest_dir.joinpath(path.name)
print(f'File to download: {path} \n')
print(f'Should download to {dest} \n')
while True:
try:
async with aioftp.Client.context('192.12.137.7', user='anonymous', port=21) as client:
async with aiofiles.open(dest, mode='ab', ) as local_file:
#Check to see if local_file exists
if await aos.path.exists(dest):
stat = await aos.stat(dest)
size = stat.st_size
else:
size = 0
logging.info(f'Starting at postition {size}')
local_file.seek(size)
async with client.download_stream(path, offset=size) as stream:
while True:
logging.info(f'Stream Connected')
async for block in stream.iter_by_block(512):
if not block:
break
await local_file.write(block)
await stream.finish()
break
except ConnectionResetError:
pass
Logging Info
PS C:\workspace\git_clones\loca_download> & C:/Anaconda3/envs/loca_download/python.exe c:/workspace/git_clones/loca_download/scripts/connect_loca_git.py
[09:40:05]: [asyncio] Using proactor: IocpProactor
File to download: /pub/dcp/archive/cmip5/loca/LOCA_2016-04-02/ACCESS1-0/16th/historical/r1i1p1/pr/pr_day_ACCESS1-0_historical_r1i1p1_19500101-19501231.LOCA_2016-04-02.16th.nc
Should download to output\ACCESS1-0\historical\pr\pr_day_ACCESS1-0_historical_r1i1p1_19500101-19501231.LOCA_2016-04-02.16th.nc
[09:40:05]: [aioftp.client] 220- **WARNING**WARNING**WARNING**WARNING**WARNING**
[09:40:05]: [aioftp.client] 220- This is a Department of Energy (DOE) computer system. DOE
[09:40:05]: [aioftp.client] 220- computer systems are provided for the processing of official
[09:40:05]: [aioftp.client] 220- U.S. Government information only. All data contained within
[09:40:05]: [aioftp.client] 220- DOE computer systems is owned by the DOE, and may be audited,
[09:40:05]: [aioftp.client] 220- intercepted, recorded, read, copied, or captured in any
[09:40:05]: [aioftp.client] 220- manner and disclosed in any manner, by authorized personnel.
[09:40:05]: [aioftp.client] 220- THERE IS NO RIGHT OF PRIVACY IN THIS SYSTEM. System personnel
[09:40:05]: [aioftp.client] 220- may disclose any potential evidence of crime found on DOE
[09:40:05]: [aioftp.client] 220- computer systems to appropriate authorities.
[09:40:05]: [aioftp.client] 220-
[09:40:05]: [aioftp.client] 220- USE OF THIS SYSTEM BY ANY USER, AUTHORIZED OR UNAUTHORIZED,
[09:40:05]: [aioftp.client] 220- CONSTITUTES CONSENT TO THIS AUDITING, INTERCEPTION, RECORDING,
[09:40:05]: [aioftp.client] 220- READING, COPYING, CAPTURING, AND DISCLOSURE OF COMPUTER ACTIVITY.
[09:40:05]: [aioftp.client] 220-
[09:40:05]: [aioftp.client] 220- **WARNING**WARNING**WARNING**WARNING**WARNING**
[09:40:05]: [aioftp.client] 220-
[09:40:05]: [aioftp.client] 220
[09:40:05]: [aioftp.client] USER anonymous
[09:40:06]: [aioftp.client] 331 Please specify the password.
[09:40:06]: [aioftp.client] PASS *****
[09:40:06]: [aioftp.client] 230 Login successful.
[09:40:06]: [root] Starting at postition 230992375
[09:40:06]: [aioftp.client] TYPE I
[09:40:06]: [aioftp.client] 200 Switching to Binary mode.
[09:40:06]: [aioftp.client] EPSV
[09:40:06]: [aioftp.client] 229 Entering Extended Passive Mode (|||35457|).
[09:40:06]: [aioftp.client] REST 230992375
[09:40:06]: [aioftp.client] 350 Restart position accepted (230992375).
[09:40:06]: [aioftp.client] RETR /pub/dcp/archive/cmip5/loca/LOCA_2016-04-02/ACCESS1-0/16th/historical/r1i1p1/pr/pr_day_ACCESS1-0_historical_r1i1p1_19500101-19501231.LOCA_2016-04-02.16th.nc
[09:40:06]: [aioftp.client] 150 Opening BINARY mode data connection for /pub/dcp/archive/cmip5/loca/LOCA_2016-04-02/ACCESS1-0/16th/historical/r1i1p1/pr/pr_day_ACCESS1-0_historical_r1i1p1_19500101-19501231.LOCA_2016-04-02.16th.nc (230992375 bytes).
[09:40:06]: [root] Stream Connected
[09:40:06]: [aioftp.client] 226 Transfer complete.
[09:40:06]: [root] Stream Connected
As you can see the code appears to be working properly, and I am getting a complete transfer. However the code does not seem to move on to the next file.
How can I write a conditional statement that checks for [aioftp.client] 226 Transfer complete
?
Which bit of code is that message coming from?
Metadata
Metadata
Assignees
Labels
No labels