Topic "Want to delete remote files before download via powershell"

Author Message
shannra
[View user's profile]

Joined: 2013-04-17
Posts: 3
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??
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
Are you looking for $session.RemoveFiles("/path/*") ?

http://winscp.net/eng/docs/library_session_removefiles
shannra
[View user's profile]

Joined: 2013-04-17
Posts: 3
Thanks for you replie, but it seemed not tor work:

I use (its only snippet from the script)
Code:
$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:
Code:
{WinSCP.SessionRemoteException: Can't get attributes of file
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
Please set Session.SessionLogPath and attach the log.
_________________
Martin Prikryl
shannra
[View user's profile]

Joined: 2013-04-17
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:

Code:

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)
.
.
.
.
.
.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
SessionLogPath is a property, not a method. So do:

Code:
$sessionOptions.SessionLogPath = ...


See http://winscp.net/eng/docs/library_session
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