Muối Nhạt's site

Make notes and share experiences

Make notes and share experiences

Các lệnh dùng FTP trên Linux command line

Sau khi Login vào Server với lệnh ftp IP/HostName, ta dùng các lệnh sau để quản lý tập tin:

Các lệnh về thư mục

cd [folder name] : chuyển thư mục
cd .. : chuyển ra thư mục ngoài
lcd [local folder] : đặt lại thư mục làm việc trên Client
dir : liệt kê nội dung thư mục hiện tại trên Server và mổ tả quyền sử dụng
ls : giống như dir nhưng không mô tả quyền sử dụng
mkdir [folder name] : tạo thư mục trên Server
rmdir [folder name} : xóa thư mục
del [file name] : xóa file trên Server
mdel/mdelete [files name] : xóa nhiều file trên Server
pwd : hiện thông tin thư mục hiện tại
rename [from] [to] : đổi tên file hoặc thư mục [from] thành [to]

Các lệnh về tập tin

bin / binary : chuyển sang chế độ truyền file theo định dạng nhị phân
ascii : chuyển sang chế độ truyền file theo định dạng văn bản
get [file name] : download file trên máy chủ (với file hình ảnh, dùng lệnh bin trước khi dùng lệnh get).
Sau khi download, file sẽ lưu tại thư mục hiện tại trên Client
mget [files name] : download nhiều files
put [file name] : Upload file lên Server. put [local file] [new file] : Upload và đổi tên là new file
mput [files name] : Uploa nhiều files lên Server.
Trước khi dùng put hoặc mput upload files lên Server, ta nên nén các file thực thi .exe .com để tránh trường hợp không upload được

Các lệnh khác

help [command] / ? / ? tênLệnh: xem hướng dẫn về lệnh
bell : mở tắt tiếng chuông khi hoàn tất lệnh
status : xem tình trạng phiên làm việc hiện tại
system : xem hệ điều hành của Server
send [LocalFileName] [ServerFileName] : gởi LocalFileName từ Client lên Server với tên mới là ServerFileName
recv [ServerFileName] [LocalFileName] : nhận ServerFileName trên Server vào lưu vào Client với tên mới là LocalFileName
close / disconnect : ngắt kết nối
quit : thoát chương trình FTP
bye : ngắt và thoát chương trình FTP
! : thoát khỏi shell FTP
open [Hostname] [port number] : kết nối đến Server với tên host là Hostname và ở cổng chỉ định

Một số ví dụ

Login vào host
Vào Command Prompt
Nhập lệnh : ftp IP hoặc Host name
Nhập Username và Password
Xem thư mục hiện tại, tạo thư mục mới là Soft, chuyển vào thư mục Soft và Upload file abc.txt
ftp> pwd
ftp> mkdir Soft
ftp> cd Soft
ftp>ascii
ftp> put abc.txt
Chuyển ra thư mục ngoài, Download file def.jpg về, liệt kê nội dung thư mục hiện tại trên Server
ftp> cd ..
ftp> bin
ftp> get def.jpg
ftp> ls
Ngắt và thoát khỏi FTP
ftp> close
ftp> quit

Ví dụ khác:

C:\website>ftp myftpsrv // kết nối đến máy chủ myftpsrv
Connected to myftpsrv.
User (ftpsrv:(none)): dt
331 User name okay, need password.
Password:
230 User logged in, proceed.

ftp> pwd // cho biết thư mục hiện tại đang làm việc!
257 “/home/dt” is current directory.

ftp> status // xem trạng thái hiện tại
Type: ascii; Verbose: On ; Bell: Off ; Prompting: On ; Globbing: On
Debugging: Off ; Hash mark printing: Off . // ascii=1

ftp> cd www // chuyển vào thư mục www
250 Directory changed to /home/dt/www

ftp> put index.html // upload file index.html lên server
200 PORT Command successful.
150 Opening ASCII mode data connection for index.html.
226 Transfer complete.
ftp: 2095 bytes sent in 0.00Seconds 2095000.00Kbytes/sec.

ftp> mkdir tools // tạo thư mục /home/dt/www/tools
257 “/home/dt/www/tools” directory created.

ftp> cd tools // chuyển vào thư mục tools
250 Directory changed to /home/dt/www/tools

ftp> lcd c:\website\tools // thay đổi lại local directory = c:\website\tools
Local directory now C:\website\tools.

ftp> bin // chuyển sang chế độ truyền file nhị phân
200 Type set to I.

ftp> mput *.* // upload tất cả các file trong c:\website\tools lên server, vào /home/www/tools/
mput test.zip? y
200 PORT Command successful.
150 Opening BINARY mode data connection for test.zip.
226 Transfer complete.
ftp: 10168 bytes sent in 0.06Seconds 169.47Kbytes/sec.
mput test.exe? y
200 PORT Command successful.
150 Opening BINARY mode data connection for test.exe.
226 Transfer complete.
ftp: 54625 bytes sent in 0.11Seconds 496.59Kbytes/sec.

ftp> ls -la // liệt kê nội dung của /home/www/tools
200 PORT Command successful.
150 Opening ASCII mode data connection for /bin/ls.
drwxr–r– 1 dt group 0 Sep 30 14:13 .
drwxr–r– 1 dt group 0 Sep 30 14:13 ..
-rwxr–r– 1 dt group 54625 Sep 30 14:14 test.exe
-rwxr–r– 1 dt group 10168 Sep 30 14:14 test.zip
226 Transfer complete.
ftp: 247 bytes received in 0.00Seconds 247000.00Kbytes/sec.

ftp> del test.exe // tôi lỡ tay upload lên file test.exe, bây giờ tôi cần phải xóa nó
250 DELE command successful.

ftp> cd .. // chuyển lên thư mục cấp trên
250 Directory changed to /home/dt/www

ftp> mkdir cgi-bin2 // tạo thư mục mới
257 “/home/dt/www/cgi-bin2” directory created.
ftp> rename cgi-bin2 cgi-bin // tôi đã nhập vào sai mất rồi, bây giờ phải đổi tên lại thôi!
350 File or directory exists, ready for destination name
250 RNTO command successful.

ftp> cd cgi-bin // chuyển vào thư mục cgi-bin
250 Directory changed to /home/dt/www/cgi-bin

ftp> lcd c:\website\cgi-bin // đặt lại local directory!
Local directory now C:\website\cgi-bin.

ftp> ascii // chuyển sang chế độ truyền file văn bản vì tôi cần upload một số file .cgi + .pl
200 Type set to A.
ftp> put test.cgi // upload file test.cgi
200 PORT Command successful.
150 Opening ASCII mode data connection for test.cgi.
226 Transfer complete.
ftp: 222 bytes sent in 0.00Seconds 222000.00Kbytes/sec.

ftp> ls -la // xem nội dung của /home/www/cgi-bin
200 PORT Command successful.
150 Opening ASCII mode data connection for /bin/ls.
drwxr–r– 1 dt group 0 Sep 30 14:16 .
drwxr–r– 1 dt group 0 Sep 30 14:16 ..
-rwxr–r– 1 dt group 222 Sep 30 14:17 test.cgi
226 Transfer complete.
ftp: 182 bytes received in 0.00Seconds 182000.00Kbytes/sec.

ftp> site chmod 755 test.cgi // đặt quyền 755(wrxx-xr-x) cho file test.cgi
ftp> ls -la // tôi liệt kê lại thư mục cgi một lần nữa
200 PORT Command successful.
150 Opening ASCII mode data connection for /bin/ls.
drwxr-xr-x 1 dt group 0 Sep 30 14:16 .
drwxr-xr-x 1 dt group 0 Sep 30 14:16 ..
-rwxr-xr-x 1 dt group 222 Sep 30 14:17 test.cgi
226 Transfer complete.
ftp: 182 bytes received in 0.00Seconds 182000.00Kbytes/sec.
ftp> bye // tất cả đã xong, bây giờ tôi có thể ngắt kết nối được rồi!
221 Goodbye!

RELATED POSTS

[Kubernetes] – Check your Helm deployments!

Here’s a very popular post about safely deploying Helm charts containing Kubernetes Deployments with automated rollbacks. Originally published in 2019, it’s still relevant today – if you encounter something that should be updated, please let us know! — The Deployment resource

Read More »
Share the Post: