SftpException: No such file; File not found.

0 votes
asked Jul 28, 2011 by dwick (180 points)
edited Jul 4, 2012

Hi,

I'm get a SftpException: No such file; File not found. when using Sftp.DeleteFile(string filename) which is especially odd because I'm first checking that the file exists.

Here's the relevant sample code:

foreach (var file in fileList)
{
    if(ftp.Connection.FileExists(file.Name))
    {
        try
        {
            ftp.Connection.DeleteFile(file.Name);
        }
        catch (SftpException ex)
        {
            Log.Error("Deletion failed.", ex);
        }
    } 
    else
    {
         Log.Debug(string.Format("'{0}' not found.", file.Name));
    }
}

Any ideas as to what's going on here?

Logs:

2011-07-29 11:26:15.991 INFO Sftp(1) Command: SSH_FXP_STAT (13, '/AY_Applicant_Records_20110728_020500_2.txt')    
2011-07-29 11:26:16.008 INFO Sftp(1) Response: SSH_FXP_ATTRS (13)    
2011-07-29 11:26:16.794 INFO Sftp(1) Command: SSH_FXP_REMOVE (14, '/AY_Applicant_Records_20110728_020500_2.txt')    
2011-07-29 11:26:16.810 INFO Sftp(1) Response: SSH_FXP_STATUS (14, 2, 'File not found')    
2011-07-29 11:26:16.838 ERROR Sftp(1) Info: Rebex.Net.SftpException: No such file; File not found.
   at wWGvS.APnbEo.sxMvMZ(BBdsJfZ , Type )
   at wWGvS.APnbEo.BQYzPz(String )
   at Rebex.Net.Sftp.DeleteFile(String remotePath)
Applies to: Rebex SFTP
commented Jul 28, 2011 by Martin Vobr (12,940 points)
edited Jul 28, 2011

Hi, could you please edit your code and show how do you declare the ftp object? I'm a bit confused, because neither Rebex.Net.Sftp nor Rebex.Net.Ftp classes contain any Connection property.

commented Jul 28, 2011 by dwick (180 points)
edited Jul 28, 2011

it's just a wrapper around the Sftp class. the Connection property returns the Sftp object internal to the wrapper.

commented Jul 29, 2011 by Lukas Pokorny (102,170 points)
edited Jul 29, 2011

Please use Sftp object's LogWriter property (as described at http://www.rebex.net/kb/logging.aspx) to create a communication log that contains the communication of both FileExists and DeleteFile methods. Then either include that in your post or mail it to support@rebex.net. The log should make it possible to see what is actually going on.

commented Jul 29, 2011 by dwick (180 points)
edited Jul 29, 2011

i added the logs

commented Aug 1, 2011 by Lukas Matyska (55,430 points)
edited Aug 1, 2011

From the log it can be seen the server succeeds to retrieve information about the file (file should exists), but fails to remove it. Can you please try to call the ftp.Connection.GetFile(file.Name, new MemoryStream()); instead of the DeleteFile method and let us know whether it failed or not.

1 Answer

+1 vote
answered Aug 1, 2011 by dwick (180 points)
edited Aug 1, 2011

I had to dispose of previously opened streams before deletion was allowed.

commented Aug 1, 2011 by Lukas Matyska (55,430 points)
edited Aug 1, 2011

Oh, that explains it. I am glad you solve it. The server response 'File not found' is a little bit confusing in this case. I think the correct response should be the 'Permission denied'.

...