랭귀지/python

[ftplib] python ftp file upload

유키공 2018. 8. 10. 09:30

[ftplib] python ftp file upload

    
import ftplib   

filename = "sample.png"
ftp = ftplib.FTP()
ftp.connect("111.111.111.111","21")    #Ftp 주소 Connect(주소 , 포트)
ftp.login("id", "password")            #login (ID, Password)
ftp.cwd("/forder/Test")                #파일 전송할 Ftp 주소 (받을 주소)
os.chdir(r"D:\\FTP_TEST\\img")    #파일 전송 대상의 주소(보내는 주소)
my_file = open(filename, 'rb')       #Open( ~ ,'r') <= Text파일은 됨, Open( ~ ,'rb') <= 이미지파일 됨
ftp.storbinary('STOR ' + filename, my_file)
my_file.close()
ftp.close()