Want to delete remote files before download via powershell

Advertisement

shannra
Joined:
Posts:
3

Want to delete remote files before download via powershell

Hello,

i try your scripts to use the .netassemply by powershell. It works perfectly. Now i want to modifie it for one day, but with no success.
I want to empty the remotefolder before i upload my files.
I search here this forum and your documentations but still now, i not find a solution.

It this possible or should i use it in another way??

Reply with quote

Advertisement

shannra
Joined:
Posts:
3

Thanks for you replie, but it seemed not tor work:

I use (its only snippet from the script)
$sessionOptions = New-Object WinSCP.SessionOptions
    $sessionOptions.Protocol = [WinSCP.Protocol]::$protocol
    $sessionOptions.HostName = $hostname
    $sessionOptions.UserName = $username
    $sessionOptions.Password = $password
    #$sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 9a:33:4f:9c:2b:5a:ad:ad:6b:f4:67:9f:11:51:d6:ab"
 
    $session = New-Object WinSCP.Session
    try
    {
        
        # Will continuously report progress of synchronization
        $session.add_FileTransferred( { FileTransferred } )
 
        # Connect
        $session.Open($sessionOptions)
        $session.RemoveFiles("/test/*")

I get then in iSE of Powershell:
{WinSCP.SessionRemoteException: Can't get attributes of file

Reply with quote

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

Please set Session.SessionLogPath and attach the log.
_________________
Martin Prikryl

Reply with quote

shannra
Joined:
Posts:
3

Its possible that i use an old version?
i only get this output, not an Logfile:

Fehler beim Aufrufen der Methode, da [WinSCP.Session] keine Methode mit dem Namen "SessionLogPath" enthlt.
in english
error by use the method because [winscp.session] no method with name "SessionLogPath"
This is hwo implement this:

try
{
    $sessionOptions = New-Object WinSCP.SessionOptions
    $sessionOptions.Protocol = [WinSCP.Protocol]::$protocol
    $sessionOptions.HostName = $hostname
    $sessionOptions.UserName = $username
    $sessionOptions.Password = $password
    #$sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 9a:33:4f:9c:2b:5a:ad:ad:6b:f4:67:9f:11:51:d6:ab"
 
    $session = New-Object WinSCP.Session
    try
    {
        
        # Will continuously report progress of synchronization
       $Session.SessionLogPath({c:\src\C:\src\Scripts\TEST\log.txt})
        $session.add_FileTransferred( { FileTransferred } )
 
        # Connect
        $session.Open($sessionOptions)
        $session.RemoveFiles("/test/*")
        $synchronizationResult = $session.SynchronizeDirectories(
            [WinSCP.SynchronizationMode]::Remote, $source, $target, $false)
.
.
.
.
.
.

Reply with quote

Advertisement

You can post new topics in this forum