Topic "Trouble in SessionRemoteException"

Author Message
zofo
[View user's profile]

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

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

Code:

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


when i try this, my code has the follow exception

Quote:

+$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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24556
Location: Prague, Czechia
The remote path needs to end with slash, when it specifies target directory only:
http://winscp.net/eng/docs/library_session_putfiles
_________________
Martin Prikryl
zofo
[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
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