2013-08-20 34 views
15

フォルダーから別のサーバーにファイルを転送するスクリプトを書く必要があります(Linux)が、ファイルを転送するスクリプトはWindows上にあり、PowerShellの代わりにscpの代替があるかどうかは疑問でした(または、PowerShellの代替SCPはありますか?

+0

PowerShellバージョン3以降を使用している場合、https://github.com/darkoperator/Posh-SSHはオプションです。 –

答えて

7

pscp.exeは現実的な選択肢ですが、私は、私はSFTPとFTPS転送のために今数年のためにRebexからライブラリを使用していますC#アプリケーションとPowerShellスクリプトの両方が大成功を収めています。彼らのパッケージにはan SCP objectも含まれていますが、私は個人的に使っていません。

無料ですが、お金はpscpです。 Rebexパッケージを選択する前に、私はPuTTYルートを検討していましたが、チームは長期的にはどんなアプリ/スクリプトにも簡単に巻き込むことができるライブラリがあれば価値があると判断しました。

+0

予算があれば、はい:-) –

+0

このブログ記事は、Rebex SFTPをPowerShellで稼働させるのに役立ちます。http://blog.rebex.net/news/archive/2008/ 09/25/how-to-use-FTP-or-SFTP-in-PowerShell.aspx –

16

Puttyというpscp.exeと呼ばれる便利なツールがあり、これは簡単にpowershellで呼び出すことができます。

以下の例では、ウィンドウからCentOSボックスへのコピー(ユーザーコード「請求書」としてログイン)と-pwスイッチのpscpを使用してパスワードを渡します。そうでなければ、生成されたコマンドウィンドウはLinuxパスワード):

Start-Process 'C:\Program Files (x86)\PuTTY\pscp.exe' -ArgumentList ("-scp -pw password C:\Document.rtf [email protected]:/home/bill/") 

PuTTY Secure Copy client 
Release 0.62 
Usage: pscp [options] [[email protected]]host:source target 
     pscp [options] source [source...] [[email protected]]host:target 
     pscp [options] -ls [[email protected]]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 
+1

スクリプトにパスワードを入力する代わりに、キーベースの認証を使用します。 – slestak

+0

公正な点は、PSCPが要求された仕事を行うことができることを示すためのちょっとした例でした:-) –

+0

ここにWindows noobがあります。私がこれを行うと、約10秒後に消える空白のコンソールウィンドウが表示され、SCP転送は発生していないように見えます。何が起こっているかもしれないかについての任意のアイデア? – jayhendren

1

".NET優しい" 方法もあります:

を使用すると、sshコマンドを実行するためにSharpSSH DLLを使用し、SCP/SFTPのtranfersを行うことができます。例えば

[Reflection.Assembly]::LoadFrom((Resolve-Path .\Tamir.SharpSSH.dll)) 

$ssh = New-Object Tamir.SharpSsh.Sftp("server","user","password") 

$ssh.Connect() 

$ssh.Put("C:\localfile","distantfile") 

$ssh.Close() 

SSH.Netライブラリがありますが、あまりにも、それは近似的に同じことを行います。

5

SCP転送にWinSCP .NET assemblyからPowerShellを使用できます。例えば

http://winscp.net/eng/docs/library_powershell#example

例では、SFTPプロトコルを使用して参照します。 SCPを使用するには、単にそれを修正する:サーバーのサポートSCPプロトコル場合けれども

$sessionOptions.Protocol = [WinSCP.Protocol]::Scp 

、それはまた、SFTPをサポート可能性があります。あなたがオプションを持っているならSFTPが良い選択です。

関連する問題