Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: script error

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
Dragan

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?
martin

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

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
Dragan

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
Dragan

Does anyone know how to turn off tmp file transfer ? I really need this urgently. Can you help?
Dragan

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
Dragan

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