赞
踩
【背景】
用putty通过ssh连接远程的Linux,可以登录正常操作,包括编辑文件等。
但是由于速度很慢,所以在putty下,通过远程Linux的vi编辑文件,反应太慢,受不了。
期望的是,可以把该文件下载到windows的本机,然后本地编辑,编辑完后,提交覆盖源文件,即可实现高效的本地编辑文件了。
【解决方案】
网上找了下,找到这个:
即通过psftp,是putty的众多的工具之一(其他的putty子工具还有PAGEANT.EXE,PLINK.EXE,PSCP.EXE,PUTTY.EXE,PUTTYGEN.EXE),可以实现我的需求,即从Linux服务器上面,上传下载文件。
【psftp用法简介】
运行psftp之前,让我们来看看其说明:
D:DevToolputty>psftp -hPuTTY Secure File Transfer (SFTP) client
Development snapshot 2011-04-07:r9125
Usage: psftp [options] [user@]host
Options:
-V print version information and exit
-pgpfp print PGP key fingerprints and exit
-b file use specified batchfile
-bc output batchfile commands
-be don’t stop batchfile processing if errors
-v show verbose messages
-load sessname Load settings from saved session
-l user connect with specified username
-P port connect to specified port
-pw passw login with specified password
-1 -2 force use of particular SSH protocol version
-4 -6 force use of IPv4 or IPv6
-C enable compression
-i key private key file for authentication
-noagent disable use of Pageant
-agent enable use of Pageant
-batch disable all interactive prompts
在windows下,双击运行psftp,即可打开psftp,运行界面就是和普通windows下面的cmd一样。
进入psftp后,输入help,可以看到其支持很多的命令:
psftp> help
! run a local command
bye finish your SFTP session
cd change your remote working directory
chmod change file permissions and modes
close finish your SFTP session but do not quit PSFTP
del delete files on the remote server
dir list remote files
exit finish your SFTP session
getdownload a file from the server to your local machine
help give help
lcd change local working directory
lpwdprint local working directory
ls list remote files
mget download multiple files at once
mkdir create directories on the remote server
mput upload multiple files at once
mv move or rename file(s) on the remote server
openconnect to a host
putupload a file from your local machine to the server
pwdprint your remote working directory
quit finish your SFTP session
reget continue downloading files
ren move or rename file(s) on the remote server
reput continue uploading files
rm delete files on the remote server
rmdir remove directories on the remote server
1. 查看具体的某个命令的语法
用help加上命令名,即可查看具体的某个命令的语法:
psftp> help open
open [@] []
Establishes an SFTP connection to a given host. Only usable
when you are not already connected to a server.
psftp> help mget
mget [ -r ] [ — ] [ … ]
Downloads many files from the server, storing each one under
the same name it has on the server side. You can use wildcards
such as “*.c” to specify lots of files at once.
If -r specified, recursively fetch files and directories.
2. 连接linux服务器
open Linux_IP_or_ServerName
去打开一个远程的Linux,后面参数是IP地址或者域名,比如:
3. 更改在Linux的所处的目录 + 查看Linux上面的文件
比如
cd /
即可切换到根目录
ls
即可查看当前文件夹的文件。
这些命令的用法和Linux下面一样,不多介绍。
4. 查看当前windows目录 + 更改为你想要的目录
psftp> lpwd
Current local directory is D:tmp
psftp> lcd C:New local directory is C:
5. 感叹号+windows的命令,实现在psftp中运行windows的命令
引用的帖子中,说无法查看本地当前文件夹的文件,其实是不对的。
其实可以通过!dir,去查看windows下当前文件夹的文件的
psftp> lcd D:tmpbatch_testNew local directory is D:tmpbatch_test
psftp> !dir Volume in drive D has no label.
Volume Serial Number is 7048-D15B
Directory of D:tmpbatch_test
04/20/2011 03:29 PM
04/20/2011 03:29 PM
04/14/2011 03:48 PM 2,876 batch_file_test.bat
1 File(s) 2,876 bytes
2 Dir(s) 35,291,792,384 bytes free
6. 从windows到Linux的上传/下载文件
psftp> ls
Listing directory /home/e516537
drwx—— 4 e516537 e516537 4096 Apr 20 06:50 .
drwxr-xr-x 19 root root 4096 Apr 14 12:20 ..
-rw——- 1 e516537 users 3356 Apr 19 03:28 .bash_history
-rw-r–r– 1 e516537 e516537 33 Mar 31 21:00 .bash_logout
-rw-r–r– 1 e516537 e516537 248 Apr 14 08:57 .bash_profile
-rw-r–r– 1 e516537 e516537 124 Mar 31 21:00 .bashrc
-rw-r–r– 1 e516537 e516537 515 Mar 31 21:00 .emacs
drwxr-xr-x 3 e516537 e516537 4096 Mar 31 21:00 .kde
drwxr-xr-x 4 e516537 e516537 4096 Mar 31 21:00 .mozilla
-rw——- 1 e516537 users 5830 Apr 20 06:50 .viminfo
-rw-r–r– 1 e516537 e516537 658 Mar 31 21:00 .zshrc
-rwxr–r– 1 e516537 users 103 Apr 20 07:11 just_for_test.txtpsftp> get just_for_test.txtremote:/home/e516537/just_for_test.txt => local:just_for_test.txt
psftp> !dir
Volume in drive D has no label.
Volume Serial Number is 7048-D15B
Directory of D:tmpbatch_test
04/20/2011 03:31 PM
04/20/2011 03:31 PM
04/14/2011 03:48 PM 2,876 batch_file_test.bat04/20/2011 03:31 PM 103 just_for_test.txt
2 File(s) 2,979 bytes
2 Dir(s) 35,291,792,896 bytes free
psftp> put batch_file_test.batlocal:batch_file_test.bat => remote:/home/e516537/batch_file_test.bat
7.用mget去批量下载多个文件(或用mput一次性上传多个文件)
psftp> cd /mnt/linuxdev/Blackfin/FWZ/carifan_15947
Remote directory is now /mnt/beta/linuxdev/Blackfin/FWZ/carifan_15947
psftp> ls
Listing directory /mnt/beta/linuxdev/Blackfin/FWZ/carifan_15947
drwxrwxrwx 1 root RandD 4096 Aug 4 21:36 .
drwxrwxrwx 1 root RandD 4096 Jul 26 04:25 ..
drwxrwxrwx 1 root RandD 4096 Jul 26 04:29 15947
-rwxrwxrwx 1 root RandD 1537 Jul 26 04:33 15947.fwr
…
-rwxrwxrwx 1 root RandD 64 Jul 26 04:33 vssver.scc
psftp> lcd D:DevToolfwzmakerfile_to_build
New local directory is D:DevToolfwzmakerfile_to_build
psftp> help
! run a local command
bye finish your SFTP session
cd change your remote working directory
。。。
ls list remote files
mget download multiple files at once
mkdir create directories on the remote server
mput upload multiple files at once
。。。
psftp> help mgetmget [ -r ] [ — ] [ … ]
Downloads many files from the server, storing each one under
the same name it has on the server side. You can use wildcards
such as “*.c” to specify lots of files at once.
If -r specified, recursively fetch files and directories.
psftp> mget -r *remote:/mnt/beta/linuxdev/Blackfin/FWZ/carifan_15947/15947/Datastrip_prefix_test.doc => local:15947Datastrip_prefix_tes
t.doc
。。。
remote:/mnt/beta/linuxdev/Blackfin/FWZ/carifan_15947/vssver.scc => local:vssver.scc
【总结】
本身Putty就是个好东西,免费,而且功能多,而这个putty的子工具psftp也很不错。有机会大家自己探索其更多的功能吧。
另外,看上面引用的那个帖子介绍,好像scp可以实现两个Linux之间的文件传输,有机会有兴趣的人,也去试试吧。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。