Error in script - could not be renamed to target file name

Advertisement

Dragan
Guest

Error in script - could not be renamed to target file name

Hello I am testing script below taken from WinSCP site but I face problem when I run that VB script. Here is the error message:


"PS C:\XXX\test> .\script.ps1
Upload of C:XXX\test\test1.xml failed: Transfer was successfully finished, but temporary transfer file
'test1.xml.filepart' could not be renamed to target file name 'test1.xml'. If the problem persists, you may try to turn
off transfer resume support."

How do I turn this off and send files as they are instead of changing them in temp?
Can you tell me what do I add to this script below and were exactly do I add it to make this script working without any errors.





Moving local files to different location after successful upload

param (
$localPath = "C:\upload\*",
$remotePath = "/home/user/",
$backupPath = "C:\backup\"
)

try
{
# Load WinSCP .NET assembly
Add-Type -Path "WinSCPnet.dll"

# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = "example.com"
$sessionOptions.UserName = "user"
$sessionOptions.Password = "mypassword"
$sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"

$session = New-Object WinSCP.Session

try
{
# Connect
$session.Open($sessionOptions)

# Upload files, collect results
$transferResult = $session.PutFiles($localPath, $remotePath)

# Iterate over every transfer
foreach ($transfer in $transferResult.Transfers)
{
# Success or error?
if ($transfer.Error -eq $Null)
{
Write-Host ("Upload of {0} succeeded, moving to backup" -f
$transfer.FileName)
# Upload succeeded, move source file to backup
Move-Item $transfer.FileName $backupPath
}
else
{
Write-Host ("Upload of {0} failed: {1}" -f
$transfer.FileName, $transfer.Error.Message)
}
}
}
finally
{
# Disconnect, clean up
$session.Dispose()
}

exit 0
}
catch [Exception]
{
Write-Host $_.Exception.Message
exit 1
}





thanks

Dragan

Reply with quote

Advertisement

Dragan
Guest

remove renaming from script

Can anyone try to modify the script for me please to transfer files without adding prefix and need of renaming it again?


Much appreciated.


Dragan

Reply with quote

Dragan
Guest

Hi prikryl


thanks for getting back to me. I found that info already giving me reason why this happens but I am failing to find the way to turn it off in this script. Could you please let me know how to modify the script not to rename file while sending?

thanks in advance

Reply with quote

Advertisement

Dragan
Guest

script error

I have added TransferOptions.ResumeSupport to my script but I get error:

The term 'TransferOptions.ResumeSupport' is not recognized as the name of a cmdlet, function, script file, or operable p
rogram. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Are you able to place this command in my script so that it fits with other commands? I have no much experience with scripting.


Regards

Dragan

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Re: script error

Dragan wrote:

I have added TransferOptions.ResumeSupport to my script but I get error:

The term 'TransferOptions.ResumeSupport' is not recognized as the name of a cmdlet, function, script file, or operable p
rogram. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
I hope you can imagine, that we cannot help you, if you do not show us the code that produces the error.

Reply with quote

Dragan
Joined:
Posts:
1

script error

I have added this line to the script "$transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::off" but it still coming up with the same error:

Upload of C:\sFTP-GiB_to_MS-XB60\test\test1.xml failed: Transfer was successfully finished, but temporary transfer file
'test1.xml.filepart' could not be renamed to target file name 'test1.xml'. If the problem persists, you may try to turn
off transfer resume support.


Here is the script

param (
$localPath = "C:\upload\*",
$remotePath = "/home/user/",
$backupPath = "C:\backup\"
)

try
{
# Load WinSCP .NET assembly
Add-Type -Path "WinSCPnet.dll"



# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = "example.com"
$sessionOptions.UserName = "user"
$sessionOptions.Password = "mypassword"
$sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"

$session = New-Object WinSCP.Session


try
{
# Connect
$session.Open($sessionOptions)


$transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::off



# Upload files, collect results
$transferResult = $session.PutFiles($localPath, $remotePath)

# Iterate over every transfer
foreach ($transfer in $transferResult.Transfers)
{
# Success or error?
if ($transfer.Error -eq $Null)
{
Write-Host ("Upload of {0} succeeded, moving to backup" -f
$transfer.FileName)
# Upload succeeded, move source file to backup
Move-Item $transfer.FileName $backupPath
}
else
{
Write-Host ("Upload of {0} failed: {1}" -f
$transfer.FileName, $transfer.Error.Message)
}
}
}
finally
{
# Disconnect, clean up
$session.Dispose()
}

exit 0
}
catch [Exception]
{
Write-Host $_.Exception.Message
exit 1
}



How do I get rid of this error message?

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum