This project is read-only.

Permission Denied on file download

Mar 18, 2011 at 9:56 PM

I am trying to download a file from the FTP site.

Here is my code. I've tested downlaoding this file from the FTP site using WINSCP with no problems due to permissions.

Any help would be great.

Thanks

            Renci.SshClient.SftpClient client3 = new Renci.SshClient.SftpClient("127.0.0.1", 22, "test", "test");
            client3.Connect();
            IEnumerable<Renci.SshClient.Sftp.SftpFile> myfileList = client3.ListDirectory("/.");
            
            foreach (Renci.SshClient.Sftp.SftpFile myFile in myfileList)
            {
                if (myFile.Name == "xslt-file.xml")
                {
                    var mem = File.Create("C:\\temp\\download\\file1.bin");
                    var asynch = client3.BeginDownloadFile("/xslt-file.xml", mem, null, null);
                    var sftpAsynch = asynch as Renci.SshClient.Sftp.SftpAsyncResult;

                    while (!sftpAsynch.IsCompleted)
                    {
                        MessageBox.Show("downloaded " + sftpAsynch.DownloadedBytes / 1024);
                    }
                    client3.EndDownloadFile(asynch);
                                    }

            }

Coordinator
Mar 19, 2011 at 2:50 PM

Hi,

 

Can you specify what exact exception does it throw?

If you using source code version can you specify what line it occurs in?

 

One thing to try is try to specify full path when you try to download the file and see if it works.

 

Thanks,

Oleg

Mar 21, 2011 at 7:43 PM

I am using the source. I am trying to get it narrowed down and will try and get your the source line I have the issue on.

 

As far as the "entire path" this file is located in the root path, so what other path can I give it?

Thanks

-Shane

Coordinator
Mar 21, 2011 at 7:48 PM

hm, well, if this file located in the root folder then I guess this is it.

 

Try to see if you can identify which line the error occure, as it multithreded you might want to put a break point in Listener function too.

Based on the error or where it occures I would like to see if there is a problem in the code, SSH protocol or something else,

 

Thanks,

Oleg

Mar 21, 2011 at 10:08 PM
Edited Mar 21, 2011 at 10:10 PM

Ok, this is what I could find.

Its not 100% what I wanted to find, but I hope it can get you closer than its getting me.

The systems calls a method called "BeginDownloadFile" in the SftpClient.cs file (line 312)

In this method, a call is made to GetCanocicalPath. It looks like this:

var fullPath = this._sftpSession.GetCanonicalPath(path);

 

This is where I am getting the error. I've tried to step as many times as I could to narrow it down. The acctuall error happens in Session.CS on the "write" method. (line 1430)

Sometimes the error will occur in the try loop, sometimes it makes it past that, but it always seems to get sent to the "rasieError" method, called from line 1440 on the "session.cs" file.

I cant find anymore infomration than that.

So, long story short, its having an issue getting the full path I guess?

 

I never make it past line 317 in sftpClient.cs (the var of fullPath never populates)

NOTE: I am using FreeSftpD as my SFTP server. This is all running on my local machine. I've tried changing the NTFS permissions with no luck.

If you have any tips of how I can find where this error is really getting thrown, I can try to help more. I dont understand how it makes it to the RaiseError method without hitting a catch.

I've stepped though this code over 50 times today to try and narrow it down.

 

Again, thanks for you help on this.

-Shane

Mar 21, 2011 at 10:19 PM

Here is a stack trace in the RaiseError method:

 

  at Renci.SshClient.Sftp.SftpCommand.SftpSession_StatusMessageReceived(Object sender, MessageEventArgs`1 e) in C:\Users\smiller2\Downloads\Renci.SshClient\Renci.SshClient\Sftp\SftpCommand.cs:line 224   at Renci.SshClient.Sftp.SftpSession.HandleMessage(StatusMessage message) in C:\Users\smiller2\Downloads\Renci.SshClient\Renci.SshClient\Sftp\SftpSession.cs:line 240   at CallSite.Target(Closure , CallSite , SftpSession , Object )   at Renci.SshClient.Sftp.SftpSession.Channel_DataReceived(Object sender, ChannelDataEventArgs e) in C:\Users\smiller2\Downloads\Renci.SshClient\Renci.SshClient\Sftp\SftpSession.cs:line 212

 

TargetSite:

 

{Void SftpSession_StatusMessageReceived(System.Object, Renci.SshClient.MessageEventArgs`1[Renci.SshClient.Sftp.Messages.StatusMessage])}

 

-Shane

Mar 21, 2011 at 10:28 PM

I decided to try and play around with WinSCP to see if I could create the same error. 

In winSCP, if I go to "change directory"

and type in the exact path "/filename.ext" I get this:

Cannot get real path for '/xstl-file.xml'.Permission denied.

Error code: 3

Error message from server: Permission denied

Request code: 16

 

Maybe this can also help...

Mar 21, 2011 at 10:37 PM

OK. new update!

I've downloaded a new SFTP server, coreFTP (the mini version)

and everything works 100% with that server.

After some google research, it seems there is an error with FreeSFTPd and windows....

 

I'm gonna call it like that, an error in FreeSftpD

 

Let me know if you want some more follow up on this.

-Shane

Coordinator
Mar 22, 2011 at 4:24 PM

Hi,

 

Thanks for tracking down this issue and for updates,

 

Sorry I couldnt responde earlier.

One thing I can add is that I do think it probably a server issue, since when I was implementing the client, I read that if you implementing the server you must be very carefull when implementing path resolution for security reason.

For example, so you dont get access to area that you not allowed to get access to. So I think in this server implementation there is an error in path resolution algortihm,

 

once again,

Thasnk for tracking this issue down.

 

Oleg