Topic "Please Help - Script Powershell - Get Files / Change Name / Move to another folder"

Author Message
vinicostasantos1

Guest


Hi guys,

Could someone please help me with this question?
I'm trying to use this site example to DOWNLOAD files but I'm having a issue:

https://winscp.net/eng/docs/script_locking_files_while_uploading#rename

I'm having a error when the script try to move the renamed file:

"Error: Error moving file 'G:\temporary_localpath\._filepart' to 'G:localpathnewfilename'
'."


Could someone please please help me with this? Here is the script:

param (
$localPath = "\localpath\",
$remotePath = "/remotepath/",
)

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

# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = "****"
$sessionOptions.UserName = "****"
$sessionOptions.Password = "****"
$sessionOptions.SshHostKeyFingerprint = "************"

$session = New-Object WinSCP.Session

try
{

$session.Open($sessionOptions)

$suffix = "_filepart"

$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::Off

$transferResult =
$session.GetFiles(($remotePath + "*.*"), ($localPath + "*.*" + $suffix), $False, $transferOptions)
$transferResult.Check()

foreach ($transfer in $transferResult.Transfers)
{
$finalName = $transfer.Destination.Substring(0, $transfer.Destination.Length - $suffix.Length)
Write-Host ("Renomeando arquivo {0} para o nome final" -f $transfer.Destination, $finalName)
$session.MoveFile($transfer.Destination, $finalName)
}

}
finally
{
# Disconnect, clean up
$session.Dispose()
}

exit 0
}
catch [Exception]
{
Write-Host ("Error: {0}" -f $_.Exception.Message)
exit 1
}
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25748
Location: Prague, Czechia
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.
Guest




#vinicostasantos1

Have you got a solution? Having the same problem.

Regards
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25748
Location: Prague, Czechia
Anonymous wrote:
Have you got a solution? Having the same problem.

If you have the same problem, attach a full session log file showing the problem, as I've asked above.
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