当前位置: 首页 > news >正文

使用SecureCRT的SFTP在WINDOWS与LINUX之间传输文件

参考文献:

http://ice-k.iteye.com/blog/1068275

http://www.cnblogs.com/chen1987lei/archive/2010/11/26/1888391.html

背景:

  有一台主机,安装了windows7,在其安装了virtualbox,然后安装了ubuntu虚拟机。在windows7上安装SecureCRT来ssh连接ubuntu虚拟机。一般在windows上面下载软件,然后通过vsftp上传到ubuntu虚拟机上。但是这样非常麻烦,现在考虑使用sftp协议来直接传输。

方案:

  使用SecureCRT软件ssh连接到ubuntu虚拟机。然后在SecureCRT上面打开SFTP会话,如下图所示:  
 

SFTP命令

  进入到sftp命令窗口以后,就可以通过sftp命令来进行文件互传的操作。下面主要介绍一下sftp命令的含义。
复制代码
sftp> help
Available commands:
ascii                          Set transfer mode to ASCII
binary                         Set transfer mode to binary
cd path                        Change remote directory to 'path'
lcd path                       Change local directory to 'path'
detail remote-path             Display system information about remote
                                 file or folder
ldetail local-path             Display system information about local
                                 file or folder
chgrp group path               Change group of file 'path' to 'group'
chmod mode path                Change permissions of file 'path' to 'mode'
chown owner path               Change owner of file 'path' to 'owner'
exit                           Quit sftp
help                           Display this help text
include filename               Include commands from 'filename'
                                 Alternate: < filename
get [-r][-a | -b] remote-path  Download file
                                 -r downloads directory recursively
                                 force ascii (-a) or binary (-b) mode
ln [-s] existingpath linkpath  Hardlink / symlink remote file
ls [options] [path]            Display remote directory listing
lls [options] [path]           Display local directory listing
mkdir path                     Create remote directory
lmkdir path                    Create local directory
mv oldpath newpath             Move remote file
lmv oldpath newpath            Move local file
open [user@]host[:port]        Connect to remote host
put [-r][-a | -b] local-path   Upload file
                                 -r uploads directory recursively
                                 force ascii (-a) or binary (-b) mode
pwd                            Display remote working directory
lpwd                           Print local working directory
quit                           Quit sftp
rename oldname newname         Rename remote file
lrename oldname newname        Rename local file
rmdir path                     Remove remote directory
lrmdir path                    Remove local directory
rm path                        Delete remote file
lrm path                       Delete local file
su username                    Substitutes the current user
                                 This is only supported with VShell for 
                                 Windows 3.5 or later.
type [transfer-mode]           Display or set file transfer mode
view remote-path               Download and open file
version                        Display protocol version
复制代码

翻译一下就是:

复制代码
sftp-- help 
可用命令: 
cd 路径                        更改远程目录到“路径” 
lcd 路径                       更改本地目录到“路径” 
chgrp group path               将文件“path”的组更改为“group” 
chmod mode path                将文件“path”的权限更改为“mode” 
chown owner path               将文件“path”的属主更改为“owner” 
exit                           退出 sftp 
help                           显示这个帮助文本 
get 远程路径                   下载文件 
ln existingpath linkpath       符号链接远程文件 
ls [选项] [路径]               显示远程目录列表 
lls [选项] [路径]              显示本地目录列表 
mkdir 路径                     创建远程目录 
lmkdir 路径                    创建本地目录 
mv oldpath newpath             移动远程文件 
open [用户@]主机[:端口]        连接到远程主机 
put 本地路径                   上传文件 
pwd                            显示远程工作目录 
lpwd                           打印本地工作目录 
quit                           退出 sftp 
rmdir 路径                     移除远程目录 
lrmdir 路径                    移除本地目录 
rm 路径                        删除远程文件 
lrm 路径                       删除本地文件 
symlink existingpath linkpath  符号链接远程文件 
version                        显示协议版本 
复制代码

我们主要用到的就是一下六个命令

复制代码
cd 路径                        更改远程目录到“路径” 
lcd 路径                       更改本地目录到“路径” 
ls [选项] [路径]               显示远程目录列表 
lls [选项] [路径]              显示本地目录列表 
put 本地路径                   上传文件 
get 远程路径                   下载文件 
复制代码

这里在详细说明一下远程目录本地目录

远程目录:ls查看到的是ubuntu虚拟机上面的目录

本地目录:lls查看到的是windows实体机上面的目录。

实例:

假设我需要实现windows下的e:\sftp\test1.txt和ubuntu下/home/enadmin/test2.txt的互换,可以进行一下操作:

put操作:windows->linux

查看目录权限

复制代码
root@BJCGNMON01:/home# ll
total 20
drwxr-xr-x  5 root    root    4096 Apr 18 15:21 ./
drwxr-xr-x 24 root    root    4096 Jan  3 14:14 ../
drwxr-xr-x  9 enadmin enadmin 4096 Apr 18 15:22 enadmin/
drwxr-xr-x  2 root    root    4096 Apr 18 15:21 sftp/--可以看到sftp的权限是root的
drwxr-xr-x  2 root    root    4096 Apr 18 14:57 test/
root@BJCGNMON01:/home# chown -R enadmin.enadmin sftp/
root@BJCGNMON01:/home# ll
total 20
drwxr-xr-x  5 root    root    4096 Apr 18 15:21 ./
drwxr-xr-x 24 root    root    4096 Jan  3 14:14 ../
drwxr-xr-x  9 enadmin enadmin 4096 Apr 18 15:22 enadmin/
drwxr-xr-x  2 enadmin enadmin 4096 Apr 18 15:21 sftp/--修改以后权限变成enadmin的了
drwxr-xr-x  2 root    root    4096 Apr 18 14:57 test/
复制代码

拷贝文件

复制代码
sftp> put test* --初始想将文件从windows系统put到ubuntu系统,发现失败,提示拒绝访问
Uploading test1.txt to /home/test1.txt
put: failed to upload e:/sftp/test1.txt. 拒绝访问。 
Uploading test2.txt to /home/test2.txt
put: failed to upload e:/sftp/test2.txt. 拒绝访问。 
Uploading test3.txt to /home/test3.txt
put: failed to upload e:/sftp/test3.txt. 拒绝访问。 
sftp> pwd --查看当前目录是/home目录,权限是root的
/home
sftp> cd /home/enadmin/ --我切换到enadmin目录下
sftp> ls
Graphs.pm             msmtp                 ntp
sent                  smokeping.tar.gz      smokepingrtt.tar.gz
smokepingrtt2.tar.gz  Target                wqy
wqy-zenhei-0.8.38-1.deb
sftp> lls
test1.txt             test2.txt             test3.txt
sftp> put test* -再次尝试将windows下的文件put到/homg/enadmin目录下,这次成功
Uploading test1.txt to /home/enadmin/test1.txt
  100% 4 bytes      4 bytes/s 00:00:00     
e:/sftp/test1.txt: 4 bytes transferred in 0 seconds (4 bytes/s)
Uploading test2.txt to /home/enadmin/test2.txt
  100% 4 bytes      4 bytes/s 00:00:00     
e:/sftp/test2.txt: 4 bytes transferred in 0 seconds (4 bytes/s)
Uploading test3.txt to /home/enadmin/test3.txt
  100% 5 bytes      5 bytes/s 00:00:00     
e:/sftp/test3.txt: 5 bytes transferred in 0 seconds (5 bytes/s)

sftp> cd /home/sftp/--在修改sftp目录权限以后,再次切换到sftp目录下
sftp> ls
sftp> lls
test1.txt             test2.txt             test3.txt
sftp> put test* --这回put成功。所以跟权限相关
Uploading test1.txt to /home/sftp/test1.txt
  100% 4 bytes      4 bytes/s 00:00:00     
e:/sftp/test1.txt: 4 bytes transferred in 0 seconds (4 bytes/s)
Uploading test2.txt to /home/sftp/test2.txt
  100% 4 bytes      4 bytes/s 00:00:00     
e:/sftp/test2.txt: 4 bytes transferred in 0 seconds (4 bytes/s)
Uploading test3.txt to /home/sftp/test3.txt
  100% 5 bytes      5 bytes/s 00:00:00     
e:/sftp/test3.txt: 5 bytes transferred in 0 seconds (5 bytes/s)
复制代码

注意点:这里需要注意权限的问题。加入我是使用enadmin账户初始连接ubuntu的,那么我put的文件只能放到文件夹权限是enadmin的目录下,不能放到文件夹权限是root的目录下。如果想放到文件夹权限是root的目录下,那么初始就使用root账户连接ubunut,然后再创建sftp会话,这样就可以了。

get操作:linux->windows

get操作没有权限设定

复制代码
sftp> pwd
/home/enadmin
sftp> lpwd
e:/Documents
sftp> lcd e:/sftp --切换目录
sftp> lls
rc.local              test1.txt             test2.txt
test3.txt
sftp> ls
Graphs.pm             msmtp                 ntp
sent                  smokeping.tar.gz      smokepingrtt.tar.gz
smokepingrtt2.tar.gz  Target                test1.txt
test2.txt             test3.txt             wqy
wqy-zenhei-0.8.38-1.deb
sftp> get Graphs.pm --下载文件到windows
Downloading Graphs.pm from /home/enadmin/Graphs.pm
  100% 13KB     13KB/s 00:00:00     
/home/enadmin/Graphs.pm: 13503 bytes transferred in 0 seconds (13 KB/s)
sftp> lls --查看windows目录
Graphs.pm             rc.local              test1.txt
test2.txt             test3.txt
sftp> 
复制代码

转载于:https://www.cnblogs.com/cxhfuujust/p/9639048.html

相关文章:

  • Elastic+logstash+filebeat做Nginx日志分析
  • Python全栈 Web(JavaScript DOM树、DOM对象、BOM对象)
  • 分布式事务柔性事务解决方案:可靠消息最终一致性(异步确保型) —— 三、生产者实战...
  • MVC过滤器详解
  • 利用ZYNQ SOC快速打开算法验证通路(6)——利用AXI总线实时配置sysGen子系统
  • 【亲测】教你如何搭建 MongoDB 复制集 + 选举原理
  • Python中For循环
  • Linux文件系统分层标准(FHS)
  • 单元测试/部署
  • 手写一个WPF-MVVM
  • 基于lfslivecd-x86-6.3-r2145安装vnc和qemu
  • elementUI树形菜单获取每一级菜单的值
  • window下启动Redis闪退问题解决
  • 安卓投屏助手(B1358)之辅助调试
  • 小程序各种功能代码片段整理---持续更新
  • JavaScript-如何实现克隆(clone)函数
  • 4个实用的微服务测试策略
  • ABAP的include关键字,Java的import, C的include和C4C ABSL 的import比较
  • android图片蒙层
  • If…else
  • JS变量作用域
  • node.js
  • Python爬虫--- 1.3 BS4库的解析器
  • Solarized Scheme
  • Spring框架之我见(三)——IOC、AOP
  • 多线程 start 和 run 方法到底有什么区别?
  • 搞机器学习要哪些技能
  • 将回调地狱按在地上摩擦的Promise
  • 离散点最小(凸)包围边界查找
  • 使用阿里云发布分布式网站,开发时候应该注意什么?
  • 小程序 setData 学问多
  • 学习Vue.js的五个小例子
  • 学习笔记DL002:AI、机器学习、表示学习、深度学习,第一次大衰退
  • 职业生涯 一个六年开发经验的女程序员的心声。
  • 湖北分布式智能数据采集方法有哪些?
  • # Maven错误Error executing Maven
  • #多叉树深度遍历_结合深度学习的视频编码方法--帧内预测
  • (32位汇编 五)mov/add/sub/and/or/xor/not
  • (4)通过调用hadoop的java api实现本地文件上传到hadoop文件系统上
  • (arch)linux 转换文件编码格式
  • (done) ROC曲线 和 AUC值 分别是什么?
  • (三)mysql_MYSQL(三)
  • (转)Linq学习笔记
  • .NET 中创建支持集合初始化器的类型
  • .net使用excel的cells对象没有value方法——学习.net的Excel工作表问题
  • /bin、/sbin、/usr/bin、/usr/sbin
  • @ 代码随想录算法训练营第8周(C语言)|Day53(动态规划)
  • @NoArgsConstructor和@AllArgsConstructor,@Builder
  • @Repository 注解
  • @SentinelResource详解
  • [ 手记 ] 关于tomcat开机启动设置问题
  • [2021ICPC济南 L] Strange Series (Bell 数 多项式exp)
  • [AIGC] Java 和 Kotlin 的区别
  • [docker] Docker的数据卷、数据卷容器,容器互联
  • [EULAR文摘] 利用蛋白组学技术开发一项蛋白评分用于预测TNFi疗效