使用Xshell中自带的传输新建文件功能实现上传下载文件
Xshell在窗口菜单下,有个“传输新建文件”的选项,可以实现在没安装或不方便安装一些Windows2Linux文件传输工具,如:
- Xftp
- FileZilla
- MobaXterm
的情况下,快速的实现Windows2Linux的文件上传和下载操作。
打开后,弹出自家Xftp的下载页面:
我们不用下载,直接点击“取消”,在弹出的如下sftp操作页中也能完成文件的上传、下载操作。
让看一看sftp都提供了哪些命令?
Host 'k8s-master' resolved to 192.168.10.202.
Connecting to 192.168.10.202:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.Your current local directory is
D:\Documents\NetSarang Computer\6\Xshell\SessionsType `help' to browse available commnands.
sftp:/home/david> help
bye finish your SFTP session
cd change your remote working directory
clear clear screen
exit finish your SFTP session
explore explore your local directory
get download a file from the server to your local machine
help give help
lcd change and/or print local working directory
lls list contents of a local directory
lpwd print your local working directory
ls list contents of a remote directory
mkdir create a directory on the remote server
mv move or rename a file on the remote server
put upload a file from your local machine to the server
pwd print your remote working directory
quit finish your SFTP session
rename move or rename a file on the remote server
rm delete a file
rmdir remove a directory on the remote server
可以看到,sftp工具提供了丰富的命令,涉及远程目录跳转、本地目录浏览、跳转本地目录、直接呼出文件夹、远程进行文件重命名等操作。
我们看看浏览本地文件、上传、下载文件怎么操作:
# 浏览本地文件
sftp:/home/david> explore# 上传本地文件到服务器
sftp:/home/david> put
Uploading apache-zookeeper-3.7.2-bin.tar.gz to remote:/home/david/apache-zookeeper-3.7.2-bin.tar.gz
sftp: sent 13.5 MB in 0.11 seconds# 下载服务器文件到本地
# lcd命令触发弹出浏览文件夹选项,选择一个希望将远程服务器上的文件,下载到本地的存储位置,如样例中指定到D盘根目录下
sftp:/home/david> lcd
Local directory is now D:\# 打印本地目录
sftp:/home/david> lpwd
Local directory is D:\# 打印远程服务器上当前目录(样例中为/home/david)下的文件列表
sftp:/home/david> ls
drwx------ 27 david david 4096 Apr 26 21:34 .
drwxr-xr-x 3 root root 19 Aug 13 2022 ..
-rw-rw-r-- 1 david david 58 Jul 1 2023 person
-rw-rw-r-- 1 david david 14198607 Apr 26 21:34 apache-zookeeper-3.7.2-bin.tar.gz
-rw-rw-r-- 1 david david 65475915 Nov 8 2023 maxwell_v2023u1108.zip# 执行下载命令 "get 远程文件1 远程文件2 远程文件n",如这里下载刚刚上传的一个文件
sftp:/home/david> get apache-zookeeper-3.7.2-bin.tar.gz
Fetching /home/david/apache-zookeeper-3.7.2-bin.tar.gz to apache-zookeeper-3.7.2-bin.tar.gz
sftp: received 13.5 MB in 0.27 seconds