My script is very simple
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = conHostName,
UserName = conUserName,
Password = conPasswort,
SshHostKeyFingerprint = conSshHostKeyFingerprint
};
using (Session session = new Session())
{
session.Open(sessionOptions);
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
TransferOperationResult transferResult;
if(modus == "download")
{
transferResult = session.GetFiles(
remoteDirectoryDownload, localDirectoryDownload, false, transferOptions);
}
else
{
transferResult = session.PutFiles(
localDirectoryUpload, remoteDirectoryUpload, false, transferOptions);
}
transferResult.Check();
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
try
{
Console.WriteLine("Delete File: {0}", transfer.FileName);
session.RemoveFiles(transfer.FileName);
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e);
}
}
}
When I do the download, then the files from the remote host would be transferred and deleted on the remote host. But when I make the upload from the local folder, then the uploads would work but the file on the local folder would not be deleted. I get no error.
I start this with my user. I am the owner of this files and I can delete them self manually.
Also when I set a breakpoint on session.RemoveFiles
, then the correct file with the correct local path would be shown.
Maybe you have a idea for me where my fail is.