FTP คืออะไร?
FTP (File Transfer Protocol) คือโปรโตคอลมาตรฐานสำหรับถ่ายโอนไฟล์ระหว่างคอมพิวเตอร์ผ่านเครือข่าย TCP/IP พัฒนาขึ้นในปี 1971 และยังใช้งานกันอย่างแพร่หลายในโลก web hosting
FTP ทำงานบน Port 21 (control channel) และ Port 20 หรือ random port (data channel) โดยมี 2 mode คือ Active Mode (client รับ connection) และ Passive Mode (server รับ connection) สำหรับ Shared Hosting มักต้องใช้ Passive Mode เพื่อผ่าน firewall ของ client
FTP vs SFTP vs FTPS ต่างกันอย่างไร?
FTP (File Transfer Protocol)
ส่งข้อมูลแบบ plaintext ไม่มีการเข้ารหัส ข้อมูล username/password และไฟล์ทั้งหมดสามารถถูกดักอ่านได้ ใช้ Port 21 ไม่แนะนำสำหรับการใช้งานจริง
FTPS (FTP Secure)
FTP ที่เพิ่มการเข้ารหัสด้วย TLS/SSL เป็น extension ของ FTP protocol ยังใช้ Port 21 แต่เพิ่ม TLS handshake ก่อนส่งข้อมูล cPanel รองรับ FTPS แบบ Explicit โดยค่าเริ่มต้น
SFTP (SSH File Transfer Protocol)
ไม่ใช่ FTP จริงๆ แต่เป็นโปรโตคอลส่งไฟล์ที่ทำงานบน SSH ใช้ Port 22 เข้ารหัสทั้งหมดตั้งแต่ต้น ปลอดภัยที่สุดในสามแบบ แต่ Shared Hosting ส่วนใหญ่ไม่ให้ SSH access
สร้าง FTP Account ใน cPanel
- เข้า cPanel > Files > FTP Accounts
- กรอก Log In: ชื่อ FTP user ที่ต้องการ (เช่น
webmaster) - ตั้ง Password ที่แข็งแรง
- กำหนด Directory: ระบุโฟลเดอร์ที่ user นี้เข้าถึงได้ (เช่น
/public_html/) - ตั้ง Quota: กำหนดพื้นที่สูงสุดหรือปล่อย Unlimited
- คลิก Create FTP Account
username จริงที่ใช้ login FTP จะเป็น [email protected] (รวม domain)
ตั้งค่า FileZilla ขั้นตอนละเอียด
ดาวน์โหลดและติดตั้ง FileZilla
ดาวน์โหลด FileZilla Client ฟรีจาก filezilla-project.org รองรับ Windows, macOS และ Linux
เพิ่ม FTP Connection ใน Site Manager
- เปิด FileZilla > File > Site Manager (Ctrl+S)
- คลิก "New Site" ตั้งชื่อ connection เช่น "MyWebsite Hosting"
- ตั้งค่าในแท็บ General:
- Protocol: FTP – File Transfer Protocol
- Host:
ftp.yourdomain.comหรือ IP ของ server - Port: 21 (ปล่อยว่างไว้ก็ได้)
- Encryption: Require explicit FTP over TLS (แนะนำ)
- Logon Type: Normal
- User:
[email protected] - Password: รหัสผ่าน FTP
- แท็บ Transfer Settings: ตั้ง Transfer mode เป็น Passive
- คลิก Connect
หน้าตาของ FileZilla
หน้าต่าง FileZilla แบ่งเป็น 4 ส่วน:
- ซ้ายบน (Local Site) — ไฟล์ในเครื่องของคุณ
- ขวาบน (Remote Site) — ไฟล์บน hosting server
- ซ้ายล่าง — รายการไฟล์ในโฟลเดอร์ที่เลือกบนเครื่อง
- ขวาล่าง — รายการไฟล์ในโฟลเดอร์ที่เลือกบน server
โครงสร้าง Directory บน Hosting
/home/username/ ← home directory ของ cPanel account
├── public_html/ ← root ของเว็บไซต์หลัก (yourdomain.com)
│ ├── index.html ← หน้าแรกของเว็บ
│ ├── index.php
│ ├── .htaccess
│ ├── wp-content/ ← (ถ้าติดตั้ง WordPress)
│ └── images/
├── logs/ ← access และ error logs
├── mail/ ← email storage
├── ssl/ ← SSL certificates
└── tmp/ ← ไฟล์ชั่วคราว
# Addon Domain จะอยู่ที่:
/home/username/public_html/addon-domain/
# หรือ
/home/username/addon-domain.com/
Permission ไฟล์ที่ถูกต้อง
Permission หรือสิทธิ์การเข้าถึงไฟล์บน Linux ใช้ตัวเลข 3 หลัก แทน Owner/Group/Others
# Permission ที่ถูกต้องสำหรับเว็บไซต์
chmod 644 *.html *.php *.css *.js # ไฟล์ทั่วไป
chmod 755 /public_html/ # directory
chmod 755 /public_html/*/ # sub-directories
chmod 640 wp-config.php # ไฟล์ config (ปลอดภัยยิ่งขึ้น)
# ตรวจสอบ permission ทุกไฟล์
find /public_html -type f -name "*.php" -perm 777
# ถ้ามีผลลัพธ์ = ไฟล์ PHP ที่มี permission 777 (อันตราย!)
# แก้ permission bulk
find /public_html -type d -exec chmod 755 {} \;
find /public_html -type f -exec chmod 644 {} \;
ตรวจสอบว่า FTP Upload สำเร็จ
# ตรวจสอบไฟล์ที่อัพโหลดจาก browser
curl -I https://yourdomain.com/filename.html
# ตรวจสอบ directory listing (ถ้า enabled)
curl https://yourdomain.com/images/
# ทดสอบ FTP connection ด้วย command line
ftp yourdomain.com
# ป้อน username และ password
# พิมพ์ ls เพื่อดูรายการไฟล์
# ตรวจสอบขนาดไฟล์ที่อัพโหลดถูกต้อง
curl -sI https://yourdomain.com/file.zip | grep content-length
แก้ปัญหาที่พบบ่อย
Error: "Connection refused" หรือ "Could not connect to server"
Firewall บนเครื่องหรือเครือข่ายอาจ block port 21 หรือ hostname ไม่ถูกต้อง
# ทดสอบ port 21 เปิดหรือไม่
telnet ftp.yourdomain.com 21
# หรือ
nc -zv ftp.yourdomain.com 21
# ลองใช้ IP address แทน hostname
# ดู IP จาก cPanel > General Information
# ลองเปลี่ยน Encryption เป็น "Only use plain FTP (insecure)"
# ชั่วคราวเพื่อทดสอบว่า TLS เป็นปัญหา
Error: "Permission denied" เมื่ออัพโหลดไฟล์
FTP user ไม่มีสิทธิ์เขียนในโฟลเดอร์นั้น หรือโฟลเดอร์ล็อคอยู่
# ใน cPanel > FTP Accounts ตรวจสอบ directory ของ FTP user
# Directory ต้องเป็น /public_html/ หรือ subdirectory ที่ต้องการ
# ตรวจสอบ permission ของโฟลเดอร์ปลายทาง
# ใน cPanel > File Manager > คลิกขวา > Change Permissions
# Directory ต้องมีค่าอย่างน้อย 755
Error: "Passive mode failed" หรือ timeout ระหว่างถ่ายโอน
Passive mode ต้องการให้ server เปิด port สูงๆ (49152-65535) ซึ่ง firewall ของ client อาจ block
# ใน FileZilla > Edit > Settings > Connection > FTP
# ลองเปลี่ยน Transfer mode จาก Passive เป็น Active
# (Active mode ทำงานได้บน network บางประเภท)
# หรือใน Windows Firewall
# เพิ่ม Inbound rule ให้ FileZilla.exe รับ connection ได้
ไฟล์อัพโหลดแล้วแต่เว็บยังเห็นเวอร์ชันเก่า
Browser cache หรือ server-side caching เก็บไฟล์เก่าไว้
# ล้าง browser cache
# Ctrl+Shift+Delete (Windows/Linux) หรือ Cmd+Shift+Delete (macOS)
# Force reload ไม่ใช้ cache
# Ctrl+Shift+R (Windows/Linux) หรือ Cmd+Shift+R (macOS)
# ตรวจสอบว่าไฟล์บน server เป็นเวอร์ชันใหม่จริง
curl -H "Cache-Control: no-cache" https://yourdomain.com/filename.html | head -20
คำถามที่พบบ่อย
FTP กับ File Manager ใน cPanel ต่างกันอย่างไร?
File Manager ใน cPanel ทำงานผ่าน browser โดยตรง เหมาะสำหรับแก้ไขไฟล์เล็กน้อยหรือดูโครงสร้าง directory ส่วน FTP เหมาะสำหรับอัพโหลดไฟล์จำนวนมาก เพราะสามารถ drag & drop และ upload หลายไฟล์พร้อมกันได้เร็วกว่า
SFTP ต้องตั้งค่าอย่างไรใน FileZilla?
ใน FileZilla Site Manager เปลี่ยน Protocol เป็น "SFTP – SSH File Transfer Protocol" Port เป็น 22 แล้วกรอก SSH username/password ต้องตรวจสอบก่อนว่า hosting ให้ SSH access หรือไม่ (Shared Hosting ส่วนใหญ่ไม่ให้)
สามารถใช้ FTP เพื่อ download backup ได้ไหม?
ได้ครับ เพียงคลิกขวาที่ไฟล์หรือโฟลเดอร์บน remote site แล้วเลือก Download แนะนำให้ backup สม่ำเสมอ โดยเฉพาะก่อนทำการเปลี่ยนแปลงสำคัญบน hosting