FTP(File Transfer Protocol, 파일 전송 프로토콜): TCP/IP 프로토콜을 가지고 서버와 클라이언트 사이의 파일 전송을 하기 위한 프로토콜이다.
storbinary(cmd, fp, blocksize, callback, rest):
- FTP 커맨드 STOR을 사용하여 FTP 클라이언트에서 FTP 서버로 파일 전송을 시작한다.
- binary 모드로 전송한다. STOR 커맨드를 보내기 전에(다음 전송은 binary image), 함수는 내부적으로 "TYPE I" 명령을 FTP 서버에 보낸다.
cmd: 사용할 FTP 명령
fp: 파일 오브젝트. 일반적으로 내장 함수 open()을 통해서 얻는다.
blocksize: 네트워크를 통해서 읽고 보낼 최대 사이즈. default size는 8192bytes다.
callback: 콜백함수. 이 함수는 전송된 모든 blocksize bytes에 대해 호출된다.
rest: 업로드를 계속해야 하는 파일의 위치
성공 메시지: "226 Transfer complete"
실패 메시지: "553 Could not create file."
예시
# Example Python program to upload a file to an FTP server
# in binary mode
from ftplib import FTP
# Create an FTP object and connect to the server
# as anonymous user
ftpObject = FTP(host="anftpserverhost");
print(ftpObject.getwelcome());
# Login to the server
ftpResponseMessage = ftpObject.login();
print(ftpResponseMessage);
# Change to the required working directory
ftpResponseMessage = ftpObject.cwd("/upload");
print(ftpResponseMessage);
# Open the file in binary mode
fileObject = open("1KB.zip", "rb");
file2BeSavedAs = "OneKB.zip"
ftpCommand = "STOR %s"%file2BeSavedAs;
# Transfer the file in binary mode
ftpResponseMessage = ftpObject.storbinary(ftpCommand, fp=fileObject);
print(ftpResponseMessage);
결과:
220 (vsFTPd 3.0.3)
230 Login successful.
250 Directory successfully changed.
226 Transfer complete.
https://pythontic.com/ftplib/ftp/storbinary
'etc' 카테고리의 다른 글
cmd 관리자 권한으로 열리게 하기 (0) | 2024.09.10 |
---|---|
리눅스에서 IP주소를 확인하는 방법 (0) | 2023.12.16 |
Train/Validation 나눠주기 (0) | 2022.04.03 |