powershell synchronize with changing file extension while downloading.

Advertisement

ivanyeung
Guest

powershell synchronize with changing file extension while downloading.

hi
i want to synchronize the local path from the remote ftp server.
on the remote server,there are jpg files,i get success with the standard synchronize method.
however,how can i changing the file extension from .jpg to let say .txt while downloading and rename it to .jpg after downloaded?

Reply with quote

Advertisement

Guest

this is my scripts

try
{
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::ftp
HostName = "XXX"
UserName = "XXX"
Password = "XXX"

}


$session = New-Object WinSCP.Session
try
{
# Will continuously report progress of synchronization
$session.add_FileTransferred( { FileTransferred($_) } )

# Connect
$session.Open($sessionOptions)
#Define the file type to downloaded
$transferoptions= New-Object WinSCP.TransferOptions
$TransferOptions.FileMask = "*.jpg;*.txt"

# Synchronize files

$synchronizationResult = $session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::local, "d:\downloads\pic\", "/pic/", $false,$false,1,$TransferOptions)

# Throw on any error
$synchronizationResult.Check()
}

finally
{
# Disconnect, clean up
$session.Dispose()
}
}
catch [Exception]
{
Write-Host ("Error: {0}" -f $_.Exception.Message)

}

Reply with quote

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

Anonymous wrote:

thanks for your reply
however Transfer to temporary filename is supported with SFTP protocol ?
OK, you are using FTP, right?
Then you would have to do everything programmatically (enumeration of files, finding differences, transfer to temporary file name, rename).

Reply with quote

Advertisement

You can post new topics in this forum