我收到此错误:
The property 'PreserveTimestamp' cannot be found on this object. Verify that the property exists and can be set.
At path\OSBU_Broker_Extract02.ps1:14
char:3
+ $session.PreserveTimestamp = $False
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
If the problem persists, turn off setting permissions or preserving timestamp. Alternatively you can turn on 'Ignore
permission errors' option.
The server does not support the operation.
我不确定应该在哪里设置变量,请参阅下面的代码:
# Load WinSCP .NET assembly
Add-Type -Path "WinSCPnet.dll"
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "[server IP]"
UserName = "[username]"
Password = ""
SshHostKeyFingerprint = "ssh-rsa 1024 ...="
}
$session = New-Object WinSCP.Session
$session.PreserveTimestamp = $False
try
{
# Connect
$session.Open($sessionOptions)
# Upload
$session.PutFiles("filename.xlsx", "/destination/").Check()
}
finally
{
# Disconnect, clean up
$session.Dispose()
}
PreserveTimestamp
是TransferOptions
类的属性,而不是Session
。
A
TransferOptions
实例应作为 Session.PutFiles
: 的第四个参数传递
# Set up transfer options
$transferOptions = New-Object WinSCP.TransferOptions -Property @{
PreserveTimestamp = $False
}
# Transfer files
$session.PutFiles("filename.xlsx", "/destination/", $False, $transferOptions).Check()
此外,一般来说,路径应该是绝对的(不仅仅是
filename.xlsx
)。