Subject: FileExists and DeleteFile Not Working (Sftp)
Date: 2023-08-07 19:33:15
From: James
Source: fileexists-deletefile-not-working-sftp
----------------------------------------------------------------------

1)  Using FileExists on an FTP site with the file there keeps returning False.  I'm using the code from the ComponentPro UltimateSftp documentation.

booResult = client.FileExists("/Update.txt")

This always returns false, for some reason.

I was able to get it to work by doing this:

For Each info As SftpFileInfo In client.ListDirectory(New NameSearchCondition("/Update.txt"))
    booResult = True
Next info

This does return True, but not sure why the first isn't working.

2)  Finding that work around, I then tried to delete the file using the documented command.

client.DeleteFile("/Update.txt")

This would also tell me that the file did not exist.

I was able to get it to work by doing this:

strFileName = "/" & txtFileName.Text
For Each info As SftpFileInfo In client.ListDirectory(New NameSearchCondition(strFileName))
    client.DeleteFile(info.Name)
Next

Again, it's a work around, but I did get it to work.

3)  Now I'm trying to get a new file to upload and it tells me I don't have access.

Dim fi As New FileStream("C:\\Update.txt", FileMode.Open)

client.UploadFile(fi, "/Update.txt")
fi.Close()

This gives me a Permission Denied error.

There's another chunk of code that pulls down all the files in the directory that I'm looking at and it works perfectly.  I have full access via WinSCP using the same credentials, so I'm kind of at a loss what is wrong.

Any help would be appreciated.

----------------------------------------------------------------------

Note: This question has been asked on the Q&A forum of Thang Dang's fraudulent ComponentPro brand
If you purchased anything from ComponentPro, you have been scammed. Contact the payment processor
who sold you the license and ask for your money back.

Back to ComponentPro Q&A Forum Index