반응형
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
- Python
- array
- SQL
- PANDAS
- matplotlib
- c#
- Excel
- Mac
- PySpark
- list
- numpy
- Tkinter
- string
- hive
- Kotlin
- math
- Apache
- Redshift
- PostgreSQL
- Github
- GIT
- google apps script
- gas
- django
- Java
- 파이썬
- Google Excel
- dataframe
- Google Spreadsheet
Archives
- Today
- Total
달나라 노트
Python ftplib : storbinary (upload file to s3) & delete (delete file) 본문
Python/Python ftplib
Python ftplib : storbinary (upload file to s3) & delete (delete file)
CosmosProject 2021. 2. 2. 21:55728x90
반응형
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
csv_to_upload = 'test.csv'
file = open(csv_to_upload, 'rb')
ftp.storbinary('STOR '+ csv_to_upload, file)
print('File list :', ftp.nlst())
file.close()
ftp.quit() # quit s3
- Output
File list : [test.csv]
s3에 file을 upload하려면 위처럼 storbinary를 사용합니다.
이때 'STOR filename'이라는 명령어를 사용합니다.
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
csv_to_upload = 'test.csv'
file = open(csv_to_upload, 'rb')
ftp.storbinary('STOR '+ csv_to_upload, file)
print('File list :', ftp.nlst())
try:
ftp.delete(target_s3_directory +'test.csv')
print('File is deleted.')
except Exception as e:
print(e)
file.close()
ftp.quit() # quit s3
- Output
File list : []
File is deleted.
delete는 s3에 존재하는 file을 삭제합니다. (directory는 삭제하지 못합니다. directory 삭제 시 rmd를 사용해야합니다.)
728x90
반응형
'Python > Python ftplib' 카테고리의 다른 글
Python ftplib : nlst (Directory 속 file list) (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