Topic "Trouble in SessionRemoteException"

Author Message
[View user's profile]

Joined: 2014-04-23
Posts: 2
Location: Mexico
I use WINSCP in C#
need send one file to remote machine, i have to the next code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WinSCP;

namespace Envio_RecepcionSFTP
    class envioSFTP
        public int sendSFTP()
                // Setup session options
                SessionOptions sessionOptions = new SessionOptions
                    Protocol = Protocol.Sftp,
                    HostName = "192.168.x.xx",
                    UserName = "user",
                    Password = "user",
                    PortNumber= xxx,
                    SshHostKeyFingerprint = "ssh-rsa 1024 b1:af:d9:3f:27:8e:22:e0:b8:88:32:xx:xx:xx:xx:xx"

                using (Session session = new Session())
                    // Connect

                    // Upload files
                    TransferOptions transferOptions = new TransferOptions();
                    transferOptions.TransferMode = TransferMode.Binary;

                    TransferOperationResult transferResult;
                    transferOptions.FilePermissions = null;
                    transferOptions.PreserveTimestamp = false;
                    transferResult = session.PutFiles(@"C:\XML\Enviar\*", "/", false, transferOptions);

                    // Throw on any error

                    // Print results
                    foreach (TransferEventArgs transfer in transferResult.Transfers)
                        Console.WriteLine("Upload of {0} succeeded", transfer.FileName);

                return 0;
            catch (Exception e)
                Console.WriteLine("Error: {0}", e);
                return 1;

this code works fine, but i need send a file to the other path for example

"transferResult = session.PutFiles(@"C:\XML\Enviar\*", "/R", false, transferOptions);"

when i try this, my code has the follow exception


+$exception {WinSCP.SessionRemoteException: Cannot overwrite remote file '/R'.

Press 'Delete' to delete the file and create new one instead of overwriting it. ---> WinSCP.SessionRemoteException: Permission denied.
Error code: 3
Error message from server: Permission denied
--- Fin del seguimiento de la pila de la excepción interna ---
en WinSCP.OperationResultBase.Check()
en Envio_RecepcionSFTP.envioSFTP.sendSFTP() en C:\Desarrollo_xxxx\Pruebas\Envio_RecepcionSFTP\Envio_RecepcionSFTP\envioSFTP.cs:línea 39}
System.Exception {WinSCP.SessionRemoteException}

That path exist on the remote machine, but i cant write on that... i hope anyone can help me

thanks a lot
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26748
Location: Prague, Czechia
The remote path needs to end with slash, when it specifies target directory only:
Martin Prikryl
[View user's profile]

Joined: 2014-04-23
Posts: 2
Location: Mexico
Thanks a lot, it works... Very Happy Very Happy Very Happy Very Happy

You can post new topics in this forum


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!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License