0 votes
by (180 points)
edited

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
by (13.3k points)
edited

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.

by (180 points)
edited

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

by (148k points)
edited

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.

by (180 points)
edited

i added the logs

by (73.6k points)
edited

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
by (180 points)
edited

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

by (73.6k points)
edited

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'.

...