ssh sftp ftp
目录 MacOS
由于学习需要,经常要登录到服务器上操作,在window系统下,有许多好用的工具,如SSH Secure Shell Client等,而MacOS系统也有许多客户端,如iterm2,File Zilla,ZOL,Shuttle等。下面介绍一下MacOS终端自带的SSH,是标准的OpenSSH client。基本用法如下:
ssh user@host #输入密码登录服务器
如果不想每次登录都输入user和host,可用alias来配置~/.ssh/config文件:
Host alias-name
HostName ip_address
Port 22
User user
HostName ip_address
Port 22
User user
下次登录时直接输入以下命令即可登录:
ssh alias-name #输入密码登录服务器
如果要本地电脑与服务器之间传输文件,则可用scp命令:
scp <local file> <remote user>@<remote machine>:<remote path> #本地文件传到服务器上
scp <remote user>@<remote machine>:<remote file> <local path> #服务器文件下载到本地
scp -r <local file> <remote user>@<remote machine>:<remote path> #本地文件夹传到服务器上
scp -r <remote user>@<remote machine>:<remote file> <local path> #服务器文件夹下载到本地
scp <remote user>@<remote machine>:<remote file> <local path> #服务器文件下载到本地
scp -r <local file> <remote user>@<remote machine>:<remote path> #本地文件夹传到服务器上
scp -r <remote user>@<remote machine>:<remote file> <local path> #服务器文件夹下载到本地
也可以通过sftp的put与get命令实现文件的上传与下载,具体命令如下;
sftp user@host #输入密码登录服务器
sftp> help #帮助信息
Available commands:
bye Quit sftp
cd path Change remote directory to 'path'
chgrp grp path Change group of file 'path' to 'grp'
chmod mode path Change permissions of file 'path' to 'mode'
chown own path Change owner of file 'path' to 'own'
df [-hi] [path] Display statistics for current directory or
filesystem containing 'path'
exit Quit sftp
get [-afPpRr] remote [local] Download file
reget [-fPpRr] remote [local] Resume download file
reput [-fPpRr] [local] remote Resume upload file
help Display this help text
lcd path Change local directory to 'path'
lls [ls-options [path]] Display local directory listing
lmkdir path Create local directory
ln [-s] oldpath newpath Link remote file (-s for symlink)
lpwd Print local working directory
ls [-1afhlnrSt] [path] Display remote directory listing
lumask umask Set local umask to 'umask'
mkdir path Create remote directory
progress Toggle display of progress meter
put [-afPpRr] local [remote] Upload file
pwd Display remote working directory
quit Quit sftp
rename oldpath newpath Rename remote file
rm path Delete remote file
rmdir path Remove remote directory
symlink oldpath newpath Symlink remote file
version Show SFTP version
!command Execute 'command' in local shell
! Escape to local shell
? Synonym for help
sftp>put /path/filename(本地主机) /path/filename(远端主机) #上传文件
sftp>get /path/filename(远端主机) /path/filename(本地主机) #下载文件
sftp> help #帮助信息
Available commands:
bye Quit sftp
cd path Change remote directory to 'path'
chgrp grp path Change group of file 'path' to 'grp'
chmod mode path Change permissions of file 'path' to 'mode'
chown own path Change owner of file 'path' to 'own'
df [-hi] [path] Display statistics for current directory or
filesystem containing 'path'
exit Quit sftp
get [-afPpRr] remote [local] Download file
reget [-fPpRr] remote [local] Resume download file
reput [-fPpRr] [local] remote Resume upload file
help Display this help text
lcd path Change local directory to 'path'
lls [ls-options [path]] Display local directory listing
lmkdir path Create local directory
ln [-s] oldpath newpath Link remote file (-s for symlink)
lpwd Print local working directory
ls [-1afhlnrSt] [path] Display remote directory listing
lumask umask Set local umask to 'umask'
mkdir path Create remote directory
progress Toggle display of progress meter
put [-afPpRr] local [remote] Upload file
pwd Display remote working directory
quit Quit sftp
rename oldpath newpath Rename remote file
rm path Delete remote file
rmdir path Remove remote directory
symlink oldpath newpath Symlink remote file
version Show SFTP version
!command Execute 'command' in local shell
! Escape to local shell
? Synonym for help
sftp>put /path/filename(本地主机) /path/filename(远端主机) #上传文件
sftp>get /path/filename(远端主机) /path/filename(本地主机) #下载文件
如果支持ftp的服务器,也可用用ftp命令登录,通过get、mget与put、mput实现文件的下载与上传:
ftp example.com
Connected to example.com.
220 Welcome to www.net.cn FTP service.
Name (example.com:$): user
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> help
Commands may be abbreviated. Commands are:
! chmod fget less mlst open pwd rhelp struct verbose
$ close form lpage mode page quit rmdir sunique xferbuf
account cr ftp lpwd modtime passive quote rstatus system ?
append debug gate ls more pdir rate runique tenex
ascii delete get macdef mput pls rcvbuf send throttle
bell dir glob mdelete mreget pmlsd recv sendport trace
binary disconnect hash mdir msend preserve reget set type
bye edit help mget newer progress remopts site umask
case epsv4 idle mkdir nlist prompt rename size unset
cd exit image mls nmap proxy reset sndbuf usage
cdup features lcd mlsd ntrans put restart status user
ftp
Connected to example.com.
220 Welcome to www.net.cn FTP service.
Name (example.com:$): user
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> help
Commands may be abbreviated. Commands are:
! chmod fget less mlst open pwd rhelp struct verbose
$ close form lpage mode page quit rmdir sunique xferbuf
account cr ftp lpwd modtime passive quote rstatus system ?
append debug gate ls more pdir rate runique tenex
ascii delete get macdef mput pls rcvbuf send throttle
bell dir glob mdelete mreget pmlsd recv sendport trace
binary disconnect hash mdir msend preserve reget set type
bye edit help mget newer progress remopts site umask
case epsv4 idle mkdir nlist prompt rename size unset
cd exit image mls nmap proxy reset sndbuf usage
cdup features lcd mlsd ntrans put restart status user
ftp