โดยการใช้ โมดูล เสริม ftplib ของ ไพทอน
โค้ด: เลือกทั้งหมด
import ftplib
session = ftplib.FTP('ftp.server.com','USERNAME','PASSWORD') # เชื่อมต่อเข้า FTP Server
file = open('mindphp.jpg','rb') # ไฟล์ที่ต้องการย้ายไปยังปลายทาง
session.storbinary('STOR mindphp.jpg', file) # ส่งไฟล์ ไปยังปลายทางและตั้งชื่อ เหมือนชื่อ เดิมกันต้นทาง
file.close() # close file and FTP
session.quit() # ปิดการเชื่อมต่อ
session.cwd('/remote/path')
เท่านี้เราก็สามารถ ย้าย ไฟล์ ไปยังอีก Server ด้วย Python ได้แล้ว
คำสั่ง FTP อื่นๆ
help or ? - list all available FTP commands
cd - change directory on the remote machine
lcd - change directory on the local machine
ls - list the names of the files and directories in the current remote directory
mkdir - create a new directory within the current remote directory
pwd - print the current working directory on the remote machine
delete - remove a file in the current remote directory
rmdir- remove a directory in the current remote directory
get - copy one file from the remote to the local machine
mget - copy multiple file from the remote to the local machine
put - copy one file from the local to the remote machine
mput - copy one file from the local to the remote machine