(10) Linux

在工作中,每次部署应用时都需要从本机Windows服务器拷贝文件到Linux上,有时还将Linux 上的文件拷到本机,

这些操作以前都是使用Ftp 工具FlashFxp 来操作的,最近就想有什么更快捷的方法没,比如直接命令操作。

结合网上查询的资料,发现 pscp 能够实现Windows 和Linux 间相互传输文件。下文将详细描述如何使用:

一、pscp 简要描述:

PSCP (PuTTY Secure Copy client)是PuTTY 提供的文件传输工具 ,通过 SSH 连接,在两台机器之间安全的传输文件,

可以用于任何 SSH(包括 SSH v1、SSH v2) 服务器。

二、下载及使用1、下载:可以从http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html下载pscp,并将其放入windows的system32 文件夹下,这样在dos命令窗口中就能直接调用使用了。2、使用(一)Windows—Linux上传文件:1)、开始→运行→cmd进入到dos模式,输入以下命令:pscp E:\javaWP\new.txt hollyfee@130.75.7.156:/home/hollyfee2)、回车后,提示输入密码,在我们输入Linux服务器上该用户的登录密码后,ew.txt文件会上传到 Linux 服务器的/home/hollyfee目录下。具体操作如下:

C:\Users\pan>pscp E:\javaWP\new.txt pjm@100.70.63.126:/home/pjm/puttyTestThe server's host key is not cached in the registry. Youhave no guarantee that the server is the computer youthink it is.The server's rsa2 key fingerprint is:ssh-rsa 2048 35:7b:11:6b:16:95:6e:4c:63:d8:17:74:ea:ec:f9:8fIf you trust this host, enter "y" to add the key toPuTTY's cache and carry on connecting.If you want to carry on connecting just once, withoutadding the key to the cache, enter "n".If you do not trust this host, press Return to abandon theconnection.Store key in cache? (y/n) ypjm@10.70.63.26's password:new.txt                   | 0 kB |   0.1 kB/s | ETA: 00:00:00 | 100%

(二)Linux—Windows下载文件:1)、开始→运行→cmd进入到dos模式,输入以下命令:pscp hollyfee@130.75.7.156:/home/hollyfee/new.txt E:\javaWP\new_copy.txt2)、回车后,提示输入密码,输入密码后文件将上传到目标机器的/home/hollyfee目录下。其中:hollyfee为linux的用户名,130.75.7.156为远程Linux主机ip地址,/home/hollyfee/new.txt为linux下的文件,E:\javaWP\new_copy.txt为保存在本地的文件。具体操作如下:

C:\Users\pan>pscp pjm@100.70.63.26:/home/pjm/puttyTest/bb.log E:\javaWP\bb_copy.logpjm@100.70.63.26's password:bb_copy.log               | 0 kB |   0.2 kB/s | ETA: 00:00:00 | 100%

—————————————————————————————————————-

需求: 将一个文件传到100台服务器同样的路径之下。

%%i %%j %%k %%l %%m %%n

10.70.63.26 22 panjinming helloworld /home/panjinming/puttyTest #Server1

pscp -l %%k -pw "%%l" -P %%j -r %activity_dir_comp% %%k@%%i:%%m

pscp -l panjinming -pwhelloworld -P22 -r E:\javaWP\newBBB.txtpanjinming@10.70.63.26:/home/panjinming/puttyTest

执行bat脚本即可:

E:\javaWP\pscp.bat

@echo offset file=E:\javaWP\newBBB.txtfor /f "tokens=1,2,3,4,5,6" %%i in (繁体.txt) do (    echo  %%i    %%j    %%k    %%l    %%m    %%n    C:\Windows\System32\pscp -l %%k -pw "%%l" -P %%j -r %file% %%k@%%i:%%m)  

E:\javaWP\繁体.txt ( 将服务器按行按照固定格式配置 )

100.70.63.26 22 pjm helloworld /home/pjm/puttyTest #Server1

命令行中进入E:\javaWP目录至 执行pscp.bat 脚本。就可以在服务器对用的路径下得到相应的文件。

——————————————————————————————————————————————————–

用最少的悔恨面对过去

(10) Linux

相关文章:

你感兴趣的文章:

标签云: