1

Closed

SftpClient deletefile/delete fails

description

using (SftpClient sftp = new SftpClient(hostName, portNumber, userName, passWord))
{
     sftp.Connect();
     sftp.Delete(remotePath);
}

Code throws "Permission Denied" error, but i have permission to delete file. I confirmed this using WinSCP both their UI and .NET library (works fine).

file attachments

Closed Jan 29, 2013 at 11:32 PM by olegkap
No response also sounds like not a library issue

comments

olegkap wrote Jan 27, 2013 at 1:32 AM

Hi,

I just did a quick test and everything works fine for me.
The reason you getting "Permission Denied" because that's an error that I receiving from the server so I simply passing it back to the user.
I would check serer log files to see if you can find some usefull information there.
Unfortunately I cannot recreate this problem from the code you provided.
If you can provide me with step to create the file on remote machine so I could try it and see for my self I can then look into it.

Thanks,
Oleg

mcpunjabi wrote Feb 2, 2013 at 8:38 PM

Unfortunately i was busy with work, so sorry for the late reply. I did some more tests and the issues seems to be with sftp.Exists(filename) function. Here is what i am using in my application:

using (SftpClient sftp = new SftpClient(hostName, portNumber, userName, passWord))
{
sftp.Connect();
if(sftp.Exists(remotePath))
sftp.Delete(remotePath);
}

Logs show that the Exists command tries to download file and fails and when it gets to the Delete call server throws the "File in Use" error. ( not the "permission denied error" like the exception shows).