The value supplied is not valid, or the property is read-only. Change the value
Hello Experts!
I am new to WinSCP and trying to get the latest files from FTP site. But I'm having errors. Please see what I am doing wrong a remote path or
Server & Protocol information
I am new to WinSCP and trying to get the latest files from FTP site. But I'm having errors. Please see what I am doing wrong a remote path or
SshHostKeyFingerprint
. I am attaching my remote path from WinSCP software.
New-Object : The value supplied is not valid, or the property is read-only. Change the value
At line:1 char:29
+ $sessionOptions = New-Object <<<< WinSCP.SessionOptions -Property @{
+ CategoryInfo : InvalidData: (:) [New-Object], Exception
+ FullyQualifiedErrorId : InvalidValue,Microsoft.PowerShell.Commands.NewObjectCommand
Server & Protocol information
Remote system = Windows_NT File transfer protocol = FTP Cryptographic protocol = TLS/SSL Explicit encryption, TLSv1 Encryption algorithm = TLSv1/SSLv3: ECDHE-RSA-AES256-SHA, 2048 bit RSA, ECDHE-RSA-AES256-SHA SSLv3 Kx=ECDH Au=RSA Enc=AES(256) Mac=SHA1 Compression = No ------------------------------------------------------------ Certificate fingerprint 5f:66:34:ad:e9:a9:8f:c2:60:79:d8:38:f6:da:7a:0b:68:d7:94:3C ------------------------------------------------------------ Can change permissions = Yes Can change owner/group = No Can execute arbitrary command = Protocol commands only Can create symbolic/hard link = No/No Can lookup user groups = No Can duplicate remote files = No Can check available space = No Can calculate file checksum = No Native text (ASCII) mode transfers = No ------------------------------------------------------------ Additional information The server supports these FTP additional features: LANG EN* UTF8 AUTH TLS;TLS-C;SSL;TLS-P; PBSZ PROT C;P; CCC HOST SIZE MDTM REST STREAM
# Load WinSCP .NET assembly Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll" # Set up session options $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::ftp HostName = "10.162.12.15" UserName = "Administrator" Password = "Admin" SshHostKeyFingerprint = "ssh-rsa 1024 5f:66:34:ad:e9:a9:8f:c2:60:79:d8:38:f6:da:7a:0b:68:d7:94:3C" } $session = New-Object WinSCP.Session try { # Connect $session.Open($sessionOptions) # Transfer files $sourcePath = "/*.*" $destPath = "D:\ReplicationViaFTPServer\" $destPathNew = "D:\FTP\Data\" $transferOptions = New-Object WinSCP.TransferOptions $transferOptions.FileMask = "*PAT*.*;*Sch*.*|*Full*.*" while ($True) { try { $synchronizationResult = $session.SynchronizeDirectories( [WinSCP.SynchronizationMode]::Local, $destPath, $sourcePath, $False, $transferOptions) $synchronizationResult.Check() Write-Host "Synchronization on folder $($destPath) succeeded!" } catch { Write-Host "Exception catched while synchronizing the folder $($destPath)" } finally { foreach ($transfer in $synchronizationResult.Transfers) { try { Copy-Item Get-Content( $destPath + $transfer.FileName) -Destination Get-Content( $destPathNew + $transfer.FileName) -Force Write-Host "Copy of file $($transfer.FileName) succeeded" } catch { Write-Host "Exception catched while copying the file $($transfer.FileName)" } } } } Write-Host "Waiting..." Start-Sleep -Seconds 5 } finally { $session.Dispose() }