반응형
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 | 31 |
Tags
- PANDAS
- c#
- 파이썬
- numpy
- Github
- PySpark
- GIT
- math
- Python
- list
- array
- Google Spreadsheet
- Excel
- matplotlib
- Mac
- hive
- PostgreSQL
- google apps script
- dataframe
- Apache
- Redshift
- gas
- django
- Tkinter
- SQL
- Google Excel
- string
- Java
- Kotlin
Archives
- Today
- Total
달나라 노트
Python ftplib : mkd (make directory) & rmd (remove directory) 본문
Python/Python ftplib
Python ftplib : mkd (make directory) & rmd (remove directory)
CosmosProject 2021. 2. 2. 21:34728x90
반응형
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)
ftp.cwd('/test1/test2/test3/')
print('New directory :', ftp.pwd())
ftp.quit() # quit s3
- Output
Current directory : /
New directory : /test1/test2/test3/
mkd는 directory를 만들어줍니다.
현재 위치 = /
기존에 /test1/test2/라는 디렉토리가 있었고,
test2 디렉토리 안에 test3라는 디렉토리를 생성합니다.
try ~ except ~ 구문을 사용한 것은 혹시나 디렉토리 생성 시 에러가 발생할 경우 에러메세지를 출력한 후 다음 코드가 진행되도록 하기 위함입니다.
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())
# delete directory
try:
ftp.rmd('/test1/test2/test3/')
print('Directory is deleted.')
except Exception as e:
print(e)
ftp.quit() # quit s3
- Output
Current directory : /
New directory : /test1/test2/test3/
Directory is deleted.
rmd로 삭제하길 원하는 디렉토리의 위치를 입력하면 해당 디렉토리가 삭제됩니다.
위 예시에선 /test1/test2/ 안에 있는 test3/ 디렉토리가 삭제됩니다.
728x90
반응형
'Python > Python ftplib' 카테고리의 다른 글
Python ftplib : storbinary (upload file to s3) & delete (delete file) (0) | 2021.02.02 |
---|---|
Python ftplib : nlst (Directory 속 file list) (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