PowerShell有替代SCP吗?

Saa*_*aad 19 powershell scp

我需要编写一个脚本,将文件从一个文件夹传输到另一个服务器(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)

  • 使用基于密钥的身份验证,而不是在脚本中输入密码。 (2认同)

alr*_*roc 9

pscp.exe是一个可行的选择,但我一直在使用Rebex的库几年来在C#应用程序和PowerShell脚本中进行SFTP和FTPS传输,取得了巨大的成功.他们的包还包括一个SCP对象,但我没有亲自使用它.

它确实需要花钱而pscp不是免费.在选择Rebex软件包之前,我曾考虑过使用PuTTY路由,但我的团队认为,从长远来看,拥有一个可以轻松插入任何应用程序/脚本的库是值得的.


sle*_*tak 5

您可以使用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是更好的选择.