반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- Apache
- numpy
- Redshift
- django
- Mac
- string
- Kotlin
- list
- Java
- math
- PANDAS
- Github
- PostgreSQL
- Excel
- SQL
- c#
- Google Excel
- array
- Tkinter
- Google Spreadsheet
- GIT
- gas
- google apps script
- matplotlib
- hive
- Python
- PySpark
- 파이썬
- dataframe
Archives
- Today
- Total
달나라 노트
Python ftplib : nlst (Directory 속 file list) 본문
728x90
반응형
import ftplib
s3_host = '11.111.111.111'
s3_user_id = 'user_1'
s3_user_password = 'pw_1'
ftp = ftplib.FTP()
ftp.encoding = 'utf-8'
ftp.connect(s3_host) # connect to s3
ftp.login(s3_user_id, s3_user_password) # login to s3
print('Current directory :', ftp.pwd())
# make directory in s3
try:
ftp.mkd('/test1/test2/test3/')
except Exception as e:
print(e)
try:
ftp.mkd('/test1/test2/test4/')
except Exception as e:
print(e)
ftp.cwd('/test1/test2/')
print('Current directory :', ftp.pwd())
# print file list in a directory
print(ftp.nlst())
# delete directory
try:
ftp.rmd('/test1/test2/test3/')
print('Already exists directory is deleted.')
except Exception as e:
print(e)
print('Current directory :', ftp.pwd())
# print file list in a directory
print('File list :', ftp.nlst():
ftp.quit() # quit s3
- Output
Current directory : /
Current directory : /test1/test2/
File list : ['test3', 'test4']
Already exists directory is deleted.
Current directory : /test1/test2/
File list : ['test4']
ftplib의 nlst는 현재 디렉토리의 file을 list의 형태로 반환해줍니다.
/test1/test2/ 디렉토리 내부에 test3/, test4/ 디렉토리를 만들었고 nlst를 사용하여 파일 리스트를 출력해보면 ['test3', 'test4']로 나옵니다.
도한 rmd로 test3/디렉토리를 삭제한 후 다시 nlst를 사용해보면, test3/가 사라지고 test4/만 나오게 됩니다.
728x90
반응형
'Python > Python ftplib' 카테고리의 다른 글
Python ftplib : storbinary (upload file to s3) & delete (delete file) (0) | 2021.02.02 |
---|---|
Python ftplib : mkd (make directory) & rmd (remove directory) (0) | 2021.02.02 |
Python ftplib : pwd (print working directory) & cwd (change working directory) (0) | 2021.02.02 |
Python ftplib : login (0) | 2021.02.02 |
Comments