The value supplied is not valid, or the property is read-only. Change the value

Advertisement

sameer12
Joined:
Posts:
6
Location:
Pakistan

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 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()
}

path.png

Reply with quote

Advertisement

sameer12
Joined:
Posts:
6
Location:
Pakistan

The value supplied is not valid, or the property is read-only. Change the value

Thanks Admin Martin
Now the errors
The value supplied is not valid, or the property is read-only. Change the value
go away finding another error
Exception catched while synchronizing the folder D:\ReplicationViaFTPServer\

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,367
Location:
Prague, Czechia

Re: The value supplied is not valid, or the property is read-only. Change the value

That's your error, it does not say anything to us.

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Reply with quote

sameer12
Joined:
Posts:
6
Location:
Pakistan

The value supplied is not valid, or the property is read-only. Change the value

HI Admin Martin,
Keep tried I am able to download the files successfully . The below code works for me, only the issue I am facing while running the script from Windows PowerShell. The Windows does not close after entering the log to sessionlog.log (file). Keep writing same information to session. In the picture attached I have only three files for testing purpose, but the it keep writing the duplicates to sessionlog.log. I want to stop writing duplication close Windows PowerShell after completing the downloads from FTP. Please help me out.
# Load WinSCP .NET assembly
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
 
# Load WinSCP .NET assembly
Add-Type -Path "WinSCPnet.dll"
 
# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Ftp
    HostName = "*****"
    PortNumber = 21
    UserName = "*******"
    Password = "******"
    FtpSecure = [WinSCP.FtpSecure]::Explicit
    TlsHostCertificateFingerprint = "5f:66:34:ad:e9:a9:8f:c2:60:79:d8:38:f6:da:7a:0b:68:d7:94:3b"
}
 
$session = New-Object WinSCP.Session 
$session.SessionLogPath = "D:\ReplicationViaFTPServer\LogBackups\Sessionlog.log"
try
{
    # Connect
    $session.Open($sessionOptions)
 
    # Transfer files
    $remotePath = "D:\FTP\*"
    
    $sourcePath = "/*.*"
    $destPath = "D:\ReplicationViaFTPServer\*.*"
    $destPathNew = "D:\FTP\Caspio\"
 
    $transferOptions = New-Object WinSCP.TransferOptions
 
    $transferOptions.FileMask = "*PAT*.*;*.TRN;*Sch*.*|*Full*.*"
 
    while ($True)
    {
        try
        {
            $transferResult = $session.GetFiles($sourcePath, $destPath, $False, $transferOptions)
            $transferResult.Check()
        }
        finally
        {
        foreach ($transfer in $transferResult.Transfers)
            {
                $session.GetFiles($transfer.FileName, $destPathNew, $False, $transferOptions)
                Write-Host "Download of $($transfer.FileName) succeeded"
            }
            $destPathNew1
        }
    }
    Write-Host "Waiting..."
    Start-Sleep -Seconds 5
}
finally
{
    $session.Dispose()
}

Description: Log keep writing the same files information continous

logKeepEntering.PNG

  • Sessionlog.log (85.95 KB, Private file)
Description: Session log information

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,367
Location:
Prague, Czechia

Re: The value supplied is not valid, or the property is read-only. Change the value

The windows does not close after entering the log to sessionlog.log (file)
I'm not sure I understand.
The program/window does not close, as you have an infinite loop there:
while ($True)

Reply with quote

Advertisement

You can post new topics in this forum