我需要編寫一個腳本來將文件從一個文件夾傳輸到另一個服務器(Linux)上,但傳輸文件的腳本在Windows上,我想知道是否有替代scp
的PowerShell(或者如果有另一個這樣做的方式)是否存在用於PowerShell的SCP替代方案?
回答
pscp.exe
是一個可行的選擇,但我一直使用庫從Rebex了幾年現在SFTP和FTPS接送我在C#應用程序和PowerShell腳本中取得巨大成功。他們的軟件包還包括an SCP object,但我沒有親自使用它。
它確實需要花費,而pscp
是免費的。在選擇Rebex軟件包之前,我考慮過使用PuTTY路線,但是我的團隊決定從長遠來看,有一個我們可以輕鬆放入任何應用/腳本的庫是值得的。
如果你有它的預算,是的:-) –
此博客文章可以幫助您獲得Rebex SFTP在PowerShell中運行http://blog.rebex.net/news/archive/2008/ 9月25日/如何使用的-FTP-或-SFTP功能於PowerShell.aspx –
有一個方便的小工具,Putty稱爲pscp.exe
這將做到這一點,並可以在PowerShell容易調用。
下面的示例將從Windows複製到CentOS盒子(以用戶代碼「bill」登錄),並使用pscp
中的-pw
開關傳遞密碼(否則,產生的命令窗口將提示輸入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
使用基於密鑰的身份驗證,而不是將密碼放在腳本中。 – slestak
公平點,這只是一個快速示例,表明PSCP可以完成所要求的工作:-) –
Windows noob here。當我這樣做時,我會得到一個空白的控制檯窗口,大約10秒鐘後消失,並且SCP傳輸似乎沒有發生。關於可能發生什麼的任何想法? – jayhendren
您可以使用PowerShell的WinSCP .NET assembly進行SCP傳輸。
例如見http://winscp.net/eng/docs/library_powershell#example
的例子使用SFTP協議。要使用SCP,只需將其修改爲:
$sessionOptions.Protocol = [WinSCP.Protocol]::Scp
雖然如果您的服務器支持SCP協議,它很可能也支持SFTP。如果您有選擇,SFTP是更好的選擇。
- 1. 是否存在適用於iOS的輕量級替代方案?
- 2. 是否有替代方案
- 3. 是否存在用於複合散列的Hash :: Util替代方案?
- 4. 是否有一個用於selection.modify()的IE替代方案?
- 5. 是否有getRunningTask API的替代方案
- 6. Python是否有JGraph的替代方案?
- 7. 是否有DynamicResource的替代方案
- 8. 是否存在快速且可預測的`SendKeys`替代方案?
- 9. 是否存在xhr.overrideMimeType()函數的跨瀏覽器替代方案?
- 10. 是否存在.closest()的替代方法?
- 11. 是否有基於Node.js的Puppet或Chef的替代方案?
- 12. 用於PHP的mysql_real_escape_string的替代方案
- 13. Apache Solr中是否有MySQL的存儲過程替代方案?
- 14. 用於java 1.4的XPath替代方案
- 15. 用於MAC的SAS替代方案
- 16. 用於Cocos2d 3.0的AppController替代方案
- 17. 適用於Android的MKOverlayView替代方案
- 18. 用於sql server的greensql替代方案
- 19. 用於ODBC的PHP bind_param替代方案?
- 20. 用於WPF的PasswordBox替代方案
- 21. 適用於Android的MailCore替代方案
- 22. 用於C++的ORG替代方案
- 23. 用於php的mysqli_stmt_get_result替代方案5.2.6
- 24. 用於WF4的WorkflowServiceHost替代方案?
- 25. 用於iPad的iPhone groupTableViewBackgroundColor替代方案
- 26. 是否存在用於記錄代碼的軟件,而不是解決方案?
- 27. 是否有替代方案在WPF中使用Background Worker?
- 28. 是否有與MongoDB一起使用的DbUnit替代方案?
- 29. 是否有使用RoleProvider的替代方案?
- 30. 是否有使用Rails.env的替代方案?
對於任何使用PowerShell版本3或更高版本的人,https://github.com/darkoperator/Posh-SSH是一個選項。 –