Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

zofo

Re: Trouble in SessionRemoteException

Thanks a lot, it works... :D :D :D :D
zofo

Trouble in SessionRemoteException

Hi
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()
        {
            try
            {
                // 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
                    session.Open(sessionOptions);

                    // 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
                    transferResult.Check();

                    // 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