อัพโหลดไฟล์ ผ่าน FTP ด้วย Python ง่ายๆ 5 บรรทัดก็ย้ายไฟล์ไปยัง Server ปลายทางได้แล้ว

แชร์ความรู้ภาษา Python ไพทอน การเขียนโปรแกรมภาษาไพทอน

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41127
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

อัพโหลดไฟล์ ผ่าน FTP ด้วย Python ง่ายๆ 5 บรรทัดก็ย้ายไฟล์ไปยัง Server ปลายทางได้แล้ว

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

อัพโหลดไฟล์ ผ่าน FTP ด้วย Python ง่ายๆ 5 บรรทัดก็ย้ายไฟล์ไปยัง Server ปลายทางได้แล้ว
โดยการใช้ โมดูล เสริม 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
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 48