我需要编写一个脚本,将文件从一个文件夹传输到另一个服务器(Linux),但是传输文件的脚本是在Windows上,我想知道是否有替代scpPowerShell(或者是否有另一种方法)这个)
Gra*_*old 21
有是带有一个方便的小工具腻子叫pscp.exe,将做到这一点,可以在PowerShell中很容易被调用.
下面的示例从Windows复制到CentOS框(以用户代码"bill"登录),并使用-pw开关pscp输入密码(否则生成的命令窗口将提示输入Linux密码):
Start-Process 'C:\Program Files (x86)\PuTTY\pscp.exe' -ArgumentList ("-scp -pw password C:\Document.rtf bill@192.168.0.28:/home/bill/")
Run Code Online (Sandbox Code Playgroud)
PuTTY Secure Copy client
Release 0.62
Usage: pscp [options] [user@]host:source target
pscp [options] source [source...] [user@]host:target
pscp [options] -ls [user@]host:filespec
Options:
-V print version information and exit
-pgpfp print PGP key fingerprints and exit
-p preserve file attributes
-q quiet, don't show statistics
-r copy directories recursively
-v show verbose messages
-load sessname Load settings from saved session
-P port connect to specified port
-l user connect with specified username
-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
-unsafe allow server-side wildcards (DANGEROUS)
-sftp force use of SFTP protocol
-scp force use of SCP protocol
Run Code Online (Sandbox Code Playgroud)
您可以使用WinSCP赋予.NET程序集从PowerShell中的SCP传输.
例如,请参阅http://winscp.net/eng/docs/library_powershell#example
该示例使用SFTP协议.要使用SCP,只需将其修改为:
$sessionOptions.Protocol = [WinSCP.Protocol]::Scp
Run Code Online (Sandbox Code Playgroud)
虽然如果您的服务器支持SCP协议,但它很可能也支持SFTP.如果您有选择,SFTP是更好的选择.
| 归档时间: |
|
| 查看次数: |
49606 次 |
| 最近记录: |