admin管理员组

文章数量:1400089

I'm connecting to an SFTP Server with FileZilla and my app using the same credentials but for whatever reason, FileZilla will allow me to download files from that site but I'm getting a permission denied from my app when using Renci ssh.

The strange thing is that I can connect, recurse through folders, list all the files, get the file details via .NET, just not download.

The ssh code is bog standard but note that I've removed a load of validation, etc... for simplicity sake:

try
{
    var sftpClient = this.GetSftpClient();

    this.ChangeDirectory(sftpClient, remoteDirectory, false);

    var file = sftpClient.Get(remoteFilename);

    var fullOutputFilename = Path.Combine(outputPath, outputFilename);

    try
    {
        using (var fileStream = System.IO.File.Create(fullOutputFilename))
        {
            sftpClient.DownloadFile(file.Name, fileStream);
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine($"Failed to open file: {file.FullName}");
        Console.WriteLine($"Exception type: {ex.GetType().Name}");
        Console.WriteLine($"Message: {ex.ToString()}");
    }

Note that I can connect to that same SFTP site using PowerShell and when checking the file's permission, I get the following:

sftp> ls -l
-rwxrwxrwx    1 0        0          104278 Mar 20 17:11 MyFile.pdf
-rwxrwxrwx    1 0        0            1791 Mar 20 17:11 MyFile.json

Can you spot anything wrong with this? As far as I tell, all the permissions look ok to me.

I'm just getting the following exception:

Failed to open file: /MyFolder/Out/MySubfolder/MyFile.json
Exception type: SftpPermissionDeniedException
Message: Permission Denied....

Any ideas why this works from FileZilla, PowerShell but not with SSH.NET? Note that I've had this code working in the past where I'm using a private key file but in this instance, I need to use a username and password.

If I need to provide anything else, please let me know but note that I don't have access to the SFTP server as this is from a third-party company.

Thanks

本文标签: cCan download file with Filezilla from SFTP server but getting permission denied from sshnetStack Overflow