[英]Count number of uploaded file using PowerShell and WinSCP .NET assembly
我有将文件从我的计算机上传到 FTP 的脚本。 但我想计算我的脚本上传了多少文件。 我使用 WinSCP 的脚本。
Add-Type -Path "WinSCPnet.dll"
$session = New-Object WinSCP.Session
try
{
# Connect
$session.DebugLogPath = "C:\forKeppLog\transfer_data_script.log"
$session.Open($sessionOptions)
#Message
Write-Host -ForegroundColor Cyan "`r`nUploading files to $servername..."
Write-Host -ForegroundColor White "Do not close this window!"
$path = "/MyuploadfilesTOFtp/"
# Transfer files
$session.PutFiles("C:\Myfileslocation\*.*", $path+"/*").Check()
}
finally
{
#Inform user
Write-Host -ForegroundColor Cyan "Files have been uploaded to $servername."
#Dispose of session
$session.Dispose()
}
我可以看到我的日志文件中上传了哪些文件,但使用起来并不友好。 我想为已上传的计数文件数获取一些变量。
我想做这样的事情
Write-Host -ForegroundColor Cyan "Files have been uploaded to $servername. Uploaded file's number is $numberofiles."
Session.PutFiles
返回TransferOperationResult
。 它具有Transfers
属性,其中包含Transfers
的集合。
$results = $session.PutFiles("C:\Myfileslocation\*.*", $path+"/*")
$results.Check() # Throws if any transfer failed
$count = $results.Transfers.Count
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.