使用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> 
复制代码

 

 

 本文转自xwdreamer博客园博客,原文链接:http://www.cnblogs.com/xwdreamer/p/3673397.html,如需转载请自行联系原作者

目录
相关文章
|
11天前
|
人工智能 Linux iOS开发
Burp Suite Professional 2025.2 (macOS, Linux, Windows) - Web 应用安全、测试和扫描
Burp Suite Professional 2025.2 (macOS, Linux, Windows) - Web 应用安全、测试和扫描
39 12
Burp Suite Professional 2025.2 (macOS, Linux, Windows) - Web 应用安全、测试和扫描
|
15天前
|
存储 网络协议 Linux
【Linux】进程IO|系统调用|open|write|文件描述符fd|封装|理解一切皆文件
本文详细介绍了Linux中的进程IO与系统调用,包括 `open`、`write`、`read`和 `close`函数及其用法,解释了文件描述符(fd)的概念,并深入探讨了Linux中的“一切皆文件”思想。这种设计极大地简化了系统编程,使得处理不同类型的IO设备变得更加一致和简单。通过本文的学习,您应该能够更好地理解和应用Linux中的进程IO操作,提高系统编程的效率和能力。
66 34
|
9天前
|
Linux
Linux文件与目录的日常
目录的切换 一般使用(”pwd“)显示当前所在的目录 比如:当前目录是在home下面的,与用户名相同的文件夹,可以使用(”cd“)命令来切换目录; 进入下载目录(”cd home/a/下载“)这种从给目录开头的一长串路经”叫做绝对路径“; 进入图片目录(”cd .. /图片/“)".."代表当前路径的上级路径,相对于当前的目录而言的”叫做相对路径“,(”.“)代表当前路径; 如果,想快速切换,上一个所在目录可以(”cd - / cd..“); 如果,想快速切换,追原始的目录可以(”cd --“); 查看目录及文件
35 14
|
16天前
|
Linux
SecureCRT连接Linux时乱码问题
本文详细介绍了在使用SecureCRT连接Linux服务器时出现乱码问题的解决方法,包括设置SecureCRT字符编码、检查和配置Linux服务器字符编码、调整终端设置等。通过这些方法,您可以有效解决SecureCRT连接Linux时的乱码问题,确保正常的终端显示和操作。希望本文能帮助您在实际操作中更好地解决类似问题,提高工作效率。
33 17
|
4天前
|
Linux Shell
Linux 将所有文件和目录名重命名为小写
Linux 将所有文件和目录名重命名为小写
20 3
|
2天前
|
Linux 网络安全 iOS开发
Metasploit Framework 6.4.49 (macOS, Linux, Windows) - 开源渗透测试框架
Metasploit Framework 6.4.49 (macOS, Linux, Windows) - 开源渗透测试框架
12 0
Metasploit Framework 6.4.49 (macOS, Linux, Windows) - 开源渗透测试框架
|
2月前
|
安全 网络协议 Linux
telnet在windows和linux上的使用方法
Telnet是一个简单且强大的网络工具,广泛用于远程管理和网络诊断。尽管存在安全风险,但在受控环境中,Telnet仍然是一个非常有用的工具。通过本文的介绍,您应该能够在Windows和Linux系统上安装并使用Telnet进行各种网络操作。
220 18
|
2月前
|
Ubuntu Linux Go
golang编译成Linux可运行文件
本文介绍了如何在 Linux 上编译和运行 Golang 程序,涵盖了本地编译和交叉编译的步骤。通过这些步骤,您可以轻松地将 Golang 程序编译成适合 Linux 平台的可执行文件,并在目标服务器上运行。掌握这些技巧,可以提高开发和部署 Golang 应用的效率。
323 14
|
2月前
|
存储 NoSQL Linux
linux积累-core文件是干啥的
核心文件是Linux系统在程序崩溃时生成的重要调试文件,通过分析核心文件,开发者可以找到程序崩溃的原因并进行调试和修复。本文详细介绍了核心文件的生成、配置、查看和分析方法
179 6
|
2月前
|
存储 NoSQL Linux
linux之core文件如何查看和调试
通过设置和生成 core 文件,可以在程序崩溃时获取详细的调试信息。结合 GDB 等调试工具,可以深入分析 core 文件,找到程序崩溃的具体原因,并进行相应的修复。掌握这些调试技巧,对于提高程序的稳定性和可靠性具有重要意义。
507 6