FTP และ SFTP คืออะไร ต่างกันอย่างไร ใช้งานอย่างไร
FTP vs SFTP: differences, security, how to use them, recommended clients, and best practices.
สารบัญ
FTP คืออะไร
FTP (File Transfer Protocol) คือ Protocol สำหรับถ่ายโอนไฟล์ระหว่าง Client และ Server ผ่าน Network ใช้ Port 21 (Control) และ Port ที่สุ่มสำหรับ Data Transfer ปัญหาหลักคือส่งข้อมูล รวม Password เป็น Plaintext ทำให้ไม่ปลอดภัยบน Network ที่ไม่น่าเชื่อถือ
FTP (File Transfer Protocol) transfers files between client and server over networks using Port 21 (control) and random data ports. The main problem: it transmits data including passwords as plaintext, making it insecure on untrusted networks.
- Port 21: FTP Control Connection
- Data Port: สุ่ม (Active) หรือ Server กำหนด (Passive)
- Plaintext: Password ส่งไม่เข้ารหัส (ไม่ปลอดภัย)
- cPanel FTP: จัดการผ่าน FTP Accounts Section
- Protocol เก่า แต่ยังใช้กันอยู่
SFTP คืออะไร
SFTP (SSH File Transfer Protocol) คือ Protocol ถ่ายโอนไฟล์ที่รัน บน SSH (Secure Shell) เข้ารหัสข้อมูลทั้งหมดรวม Authentication ใช้ Port 22 เดียวกับ SSH ปลอดภัยกว่า FTP มาก แนะนำให้ใช้ SFTP แทน FTP เสมอถ้าเป็นไปได้
SFTP (SSH File Transfer Protocol) transfers files over SSH (Secure Shell), encrypting all data including authentication. Uses Port 22 (same as SSH). Much more secure than FTP — always prefer SFTP over FTP when possible.
- Port 22: เดียวกับ SSH
- Encrypted: ทุกอย่างรวม Password เข้ารหัส
- Authentication: Password หรือ SSH Key
- ต้องการ SSH Access บน Server
- Client เดียวกัน (FileZilla) ใช้ได้ทั้ง FTP และ SFTP
FTP vs SFTP ต่างกันอย่างไร
ความต่างหลัก: FTP ไม่เข้ารหัส ส่ง Password เป็น Plaintext ใช้ Port 21 SFTP เข้ารหัสด้วย SSH ใช้ Port 22 FTP ใช้งานบน Shared Hosting ง่ายกว่าเพราะไม่ต้องการ SSH Access บาง Shared Hosting ไม่มี SFTP ให้ FTPS คือ FTP บน SSL เป็นทางเลือกกลาง
Key differences: FTP is unencrypted, sends passwords as plaintext, uses Port 21. SFTP is SSH-encrypted, uses Port 22. FTP is easier on shared hosting not requiring SSH access. Some shared hosts don't offer SFTP. FTPS is FTP over SSL — a middle option.
- FTP: ง่าย แต่ไม่ปลอดภัย Port 21
- SFTP: ปลอดภัย ต้องการ SSH Port 22
- FTPS: FTP + SSL ปลอดภัยกว่า FTP แต่ซับซ้อนกว่า
- Shared Hosting: มักให้ FTP และ FTPS
- VPS: แนะนำ SFTP + ปิด FTP ธรรมดา
FTP Client ที่แนะนำ
FileZilla: ฟรี Open Source ดีที่สุด รองรับ FTP, SFTP, FTPS WinSCP: Windows ฟรี ดีมาก รองรับ SFTP/SCP Cyberduck: Mac/Windows ฟรี UI ดี Transmit: Mac ดีที่สุดสำหรับ Mac แต่เสียเงิน Command Line: sftp และ scp ใน Terminal
FileZilla: free open source, best overall, supports FTP/SFTP/FTPS. WinSCP: free Windows client, excellent SFTP/SCP support. Cyberduck: free Mac/Windows with good UI. Transmit: best Mac client but paid. Command line: sftp and scp in Terminal.
- FileZilla: ฟรี ดีที่สุด ทุก Platform
- WinSCP: Windows ฟรี เหมาะสำหรับ SFTP
- Cyberduck: Mac/Windows ฟรี UI สวย
- Transmit: Mac เสียเงิน แต่เร็วและดีมาก
- sftp Command: Terminal ง่ายสำหรับ Dev
ตั้งค่า FTP ใน Hosting
ใน cPanel ไปที่ FTP Accounts → สร้าง Username, Password, Directory ที่อนุญาต และ Quota FileZilla ใส่ Host (domain หรือ IP), Username, Password, Port (21 สำหรับ FTP, 22 สำหรับ SFTP) เลือก Protocol ที่ถูกต้อง
In cPanel, go to FTP Accounts → create Username, Password, allowed Directory, and Quota. In FileZilla, enter Host (domain or IP), Username, Password, Port (21 for FTP, 22 for SFTP), and select the correct protocol.
- cPanel → FTP Accounts → Create
- กำหนด Directory: / (ทั้งหมด) หรือ /public_html
- Quota: จำกัด Storage ที่ใช้ได้
- FileZilla: Site Manager → เพิ่ม FTP Connection
- SFTP ใน FileZilla: Protocol → SFTP, Port 22
Passive vs Active FTP Mode
Firewall มักบล็อก Active FTP Mode เพราะ Server เป็นคนเริ่ม Data Connection ไปที่ Client Passive Mode: Client เริ่ม Data Connection เอง ผ่าน Firewall ได้ง่ายกว่า ถ้าเชื่อมต่อ FTP ไม่ได้ให้ลอง Passive Mode ก่อน
Firewalls often block Active FTP Mode because the server initiates the data connection to the client. Passive Mode: the client initiates the data connection, passing through firewalls more easily. If FTP connection fails, try Passive Mode first.
- Active FTP: Server → Client Data Connection (Firewall Block)
- Passive FTP: Client → Server Data Connection (Firewall OK)
- FileZilla: Transfer → Passive Mode
- แนะนำ: ใช้ Passive Mode เสมอ
- บน Hosting ส่วนใหญ่ต้องใช้ Passive
ความปลอดภัย FTP/SFTP
ถ้าใช้ FTP ควรใช้ FTPS (FTP over SSL) หรือ SFTP แทน ปิด Plain FTP ถ้า VPS ของตัวเอง จำกัด FTP Access ด้วย IP Whitelist ใช้ Password แข็งแกร่งหรือ SSH Key Authentication สำหรับ SFTP ตรวจสอบ FTP Log สม่ำเสมอ
Use FTPS or SFTP instead of plain FTP. Disable plain FTP on your own VPS. Restrict FTP access with IP whitelisting. Use strong passwords or SSH Key Authentication for SFTP. Regularly check FTP logs.
- ห้ามใช้ FTP ธรรมดาบน Public Network
- SFTP/FTPS: เข้ารหัส Password และข้อมูล
- SSH Key: ปลอดภัยกว่า Password Authentication
- IP Whitelist: จำกัด IP ที่ Connect FTP ได้
- ตรวจ Log: /var/log/vsftpd.log หรือ cPanel Log
การใช้ FTP ทั่วไปใน Hosting
อัพโหลดไฟล์เว็บไซต์ (HTML, PHP, CSS, JS), ดาวน์โหลด Backup ไฟล์, Edit ไฟล์โดยตรง (บาง Client ทำได้), ย้ายไฟล์ระหว่าง Directory, อัพโหลดรูปภาพจำนวนมากในครั้งเดียว และ Deploy Code จาก Local ไป Production
Common FTP uses in hosting: uploading website files (HTML, PHP, CSS, JS), downloading file backups, editing files directly (some clients support this), moving files between directories, bulk image uploads, and deploying code from local to production.
- อัพโหลดไฟล์: Drag and Drop ใน FileZilla
- ดาวน์โหลด Backup: ดึงไฟล์ทั้งหมดออกมา
- Edit ไฟล์: Right Click → View/Edit ใน FileZilla
- Deploy Code: อัพไฟล์ใหม่ทับของเก่า
- Batch Upload: อัพหลายไฟล์พร้อมกัน
FTPS คืออะไร
FTPS (FTP Secure หรือ FTP over SSL/TLS) คือ FTP ที่เพิ่ม Encryption ด้วย SSL/TLS ต่างจาก SFTP (ที่ใช้ SSH) Explicit FTPS: เริ่มต้นเป็น FTP แล้ว Upgrade SSL Implicit FTPS: SSL ตั้งแต่ต้น Port 990 ซับซ้อนกว่า FTP ธรรมดาแต่ปลอดภัยกว่า
FTPS (FTP Secure or FTP over SSL/TLS) adds SSL/TLS encryption to FTP — different from SFTP (which uses SSH). Explicit FTPS: starts as FTP then upgrades to SSL. Implicit FTPS: SSL from the start on Port 990. More complex than plain FTP but more secure.
- FTPS Explicit: Port 21 → Upgrade SSL
- FTPS Implicit: Port 990 SSL ตั้งแต่ต้น
- ต่างจาก SFTP: ใช้ SSL ไม่ใช่ SSH
- cPanel: FTPS ผ่าน Port 21 (Explicit)
- FileZilla: Protocol → FTP + Require Explicit TLS