I am using WinSCP dll with VB.net to connect to my Windows 2022 Server. I installed FTP server to enable FTP in the server. Everything seems fine. I can upload, move, delete files and folders using FileZilla client from a remote computer.
Using the same user credentials and mapping to the same root folder to which this user has permissions, I can list folders, create folders and upload files to the root folder (/).
However, when I try to upload files to any folder in the same root folder, I get the permission denied error.
I cannot figure out why this is happening.
my session options are as follows:
.Protocol = Protocol.Ftp
.PortNumber = 21
.FtpSecure = FtpSecure.Explicit
.GiveUpSecurityAndAcceptAnyTlsHostCertificate = True
I was not able to connect until I added that last line. I am also not able to connect using SFTP - Its not available on my Filezilla server version.
And my session
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
session.Open(sessionOptions)
' Upload files
Dim transferOptions As New TransferOptions
transferOptions.TransferMode = TransferMode.Automatic
transferOptions.OverwriteMode = OverwriteMode.Overwrite
transferOptions.FilePermissions = New FilePermissions With {.Octal = "775"}
I added that last line to try and apply some permissions but nothing changed
session.CreateDirectory(remote)
'this works all the time for remote = "/Root", "/Root/New", "/Root/New/New2", etc
Dim transferResult As TransferOperationResult
transferResult = session.PutFiles(local, remote, False, transferOptions)
'this uploads files to remote = "/",
'but fails where remote = "/New", "/New/New2", etc
'even when I created a folder 'manually' in the root folder and applied all permisions,
'it still fails with the same error message
transferResult.Check()
In FileZilla server, I have applied Read+Write permissions to the user on the root folder In Windows Server 2022, I have allowed all permissions to this root folder
This is the error message that I am getting:
Copying files to remote side failed. Permission denied
The remotePath argument of the Session.PutFiles method is:
Full path to upload the file to. When uploading multiple files, the filename in the path should be replaced with operation mask or omitted (path ends with slash).
So the remote should be like "/New/", "/New/New2/", ... (or "/New/*"...).
See the official example for uploading files with WinSCP .NET assembly.
Side note: Setting GiveUpSecurityAndAcceptAnyTlsHostCertificate (as the name says) is insecure. Instead, use TlsHostCertificateFingerprint. Or use a certificate signed by a trusted authority.