Re: Trouble in SessionRemoteException
Thanks a lot, it works... :D :D :D :D
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;
}
}
}
}
"transferResult = session.PutFiles(@"C:\XML\Enviar\*", "/R", false, transferOptions);"
+$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}