【发布时间】:2021-02-11 18:29:51
【问题描述】:
我有将文件从我的计算机上传到 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."
【问题讨论】:
标签: .net powershell ftp winscp winscp-net