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

Author Message
Dragan

Guest


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
Advertisements
Dragan

Guest


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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
See https://winscp.net/eng/docs/message_transfer_finished_could_not_rename
_________________
Martin Prikryl
Dragan

Guest


Does anyone know how to turn off tmp file transfer ? I really need this urgently. Can you help?
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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
The answer is just a one click away:
https://winscp.net/eng/docs/ui_pref_resume#temporary

Use TransferOptions.ResumeSupport property.
https://winscp.net/eng/docs/library_transferoptions
Dragan

Guest


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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
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.
Dragan
[View user's profile]

Joined: 2015-03-24
Posts: 1
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?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
Dragan wrote:
I have added this line to the script "$transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::off" but it still coming up with the same

You do not use the $transferOptions anywhere. And your assignment syntax is a nonsense anyway.

See for example:
https://winscp.net/eng/docs/library_powershell#example
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License