PowerShell/FTP
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
-[[PowerShellを使用してファイルをSFTPにアップロードします...
-[[Powershellを使ってFTPでデータ取得:https://qiita.com/ar...
*実装 [#r42acf4c]
**WinSCP使用 [#n5bbf356]
-[[Using WinSCP .NET Assembly from PowerShell:https://win...
***[[Session Class - WinSCP:https://winscp.net/eng/docs/l...
-[[Session.Open Method:https://winscp.net/eng/docs/librar...
-[[Session.Close Method:https://winscp.net/eng/docs/libra...
-[[Session.GetFiles Method:https://winscp.net/eng/docs/li...
-[[Session.GetFilesToDirectory Method:https://winscp.net/...
-[[Session.PutFiles Method:https://winscp.net/eng/docs/li...
-[[Session.PutFilesToDirectory Method:https://winscp.net/...
***実装例 [#dc615217]
-[[WinSCPを自動化しても別にかまわんのだろ:https://qiita.c...
-[[【さくらVPS】PowerShellでデータをバックアップする【Win...
***テストスクリプト [#u3d052c3]
#
# SFTP TestScript with WinSCP
# 1) upload files.
# 2) download 1) files.
#
# reference)
# https://qiita.com/mima_ita/items/35261ec39c3c587210d8
# https://winscp.net/eng/docs/library_session
#
# Set TestPath
$testDirectory = Get-Date -Format "yyyyMMdd_HHmm"
$uploadLocalPath = "C:\var\test\upload"
$downloadLocalPath = "C:\var\test\download\${testDirecto...
try
{
# Load WinSCP .NET assembly
Add-Type -Path 'C:\Program Files (x86)\WinSCP\WinSCP...
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions -...
Protocol = [WinSCP.Protocol]::Sftp
HostName = "localhost"
UserName = "test"
Password = "XXXXXXXX"
GiveUpSecurityAndAcceptAnySshHostKey = $True
}
$session = New-Object WinSCP.Session
try
{
# Connect
$session.Open($sessionOptions)
# Force binary mode transfer
$transferOptions = New-Object WinSCP.TransferOpt...
$transferOptions.TransferMode = [WinSCP.Transfer...
# Create Remote TestDirectory
if (!$session.FileExists($testDirectory)) {
$session.CreateDirectory($testDirectory)
}
# Upload files to TestDirectory
$transferResult =
$session.PutFiles($uploadLocalPath, $testDir...
$transferResult.Check()
# Download files from TestDirectory
if (!(Test-Path $downloadLocalPath)) {
New-Item $downloadLocalPath -ItemType Directory
}
$transferResult =
$session.GetFiles($testDirectory, $downloadL...
# Throw on any error to emulate the default "opt...
$transferResult.Check()
}
finally
{
# Disconnect, clean up
$session.Dispose()
}
exit 0
}
catch
{
Write-Host "Error: $($_.Exception.Message)"
exit 1
}
終了行:
-[[PowerShellを使用してファイルをSFTPにアップロードします...
-[[Powershellを使ってFTPでデータ取得:https://qiita.com/ar...
*実装 [#r42acf4c]
**WinSCP使用 [#n5bbf356]
-[[Using WinSCP .NET Assembly from PowerShell:https://win...
***[[Session Class - WinSCP:https://winscp.net/eng/docs/l...
-[[Session.Open Method:https://winscp.net/eng/docs/librar...
-[[Session.Close Method:https://winscp.net/eng/docs/libra...
-[[Session.GetFiles Method:https://winscp.net/eng/docs/li...
-[[Session.GetFilesToDirectory Method:https://winscp.net/...
-[[Session.PutFiles Method:https://winscp.net/eng/docs/li...
-[[Session.PutFilesToDirectory Method:https://winscp.net/...
***実装例 [#dc615217]
-[[WinSCPを自動化しても別にかまわんのだろ:https://qiita.c...
-[[【さくらVPS】PowerShellでデータをバックアップする【Win...
***テストスクリプト [#u3d052c3]
#
# SFTP TestScript with WinSCP
# 1) upload files.
# 2) download 1) files.
#
# reference)
# https://qiita.com/mima_ita/items/35261ec39c3c587210d8
# https://winscp.net/eng/docs/library_session
#
# Set TestPath
$testDirectory = Get-Date -Format "yyyyMMdd_HHmm"
$uploadLocalPath = "C:\var\test\upload"
$downloadLocalPath = "C:\var\test\download\${testDirecto...
try
{
# Load WinSCP .NET assembly
Add-Type -Path 'C:\Program Files (x86)\WinSCP\WinSCP...
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions -...
Protocol = [WinSCP.Protocol]::Sftp
HostName = "localhost"
UserName = "test"
Password = "XXXXXXXX"
GiveUpSecurityAndAcceptAnySshHostKey = $True
}
$session = New-Object WinSCP.Session
try
{
# Connect
$session.Open($sessionOptions)
# Force binary mode transfer
$transferOptions = New-Object WinSCP.TransferOpt...
$transferOptions.TransferMode = [WinSCP.Transfer...
# Create Remote TestDirectory
if (!$session.FileExists($testDirectory)) {
$session.CreateDirectory($testDirectory)
}
# Upload files to TestDirectory
$transferResult =
$session.PutFiles($uploadLocalPath, $testDir...
$transferResult.Check()
# Download files from TestDirectory
if (!(Test-Path $downloadLocalPath)) {
New-Item $downloadLocalPath -ItemType Directory
}
$transferResult =
$session.GetFiles($testDirectory, $downloadL...
# Throw on any error to emulate the default "opt...
$transferResult.Check()
}
finally
{
# Disconnect, clean up
$session.Dispose()
}
exit 0
}
catch
{
Write-Host "Error: $($_.Exception.Message)"
exit 1
}
ページ名: