I am currently uploading files to a unix server using SFTP using Renci SSH.NET, and it works fine. However, I now would like to upload files to a "Symlink container", and then create a symlink in another directory pointing to these files. Is that possible? I haven't found a class to manage symlinks, so how can this be achieved?
2 Answers
Use the SftpClient.SymbolicLink
method.
public void SymbolicLink(string path, string linkPath)
Note that the meaning of the paths is a mess. The most common SFTP server, the OpenSSH, is buggy and uses the paths in a wrong order. Many other SFTP servers follow the bug for a compatibility. But not all. So you have to test which order is used by your servers.
See

- 188,800
- 56
- 490
- 992
-
Thank you Martin, this works, however, what if I want to delete the link (not the real target, only the link) again? SftpClient.Delete throws an exception ("Failure"). – Erik May 18 '16 at 05:06
-
1It should work. Post a new question with a full code and more information. – Martin Prikryl May 18 '16 at 05:50
I have worked with SSH.net and I don't have found something about symlinks. However I found that SSH.net supports custom commands therefor you can write the Linux command (I think that it's ln) to create the symblink.
In this url you can get an example about how to use a custom command with SSH How to run several commands with SSH.Net?
Maybe if you need to create a lot symlinks, you can create a class or you can download the source code and add a new method.
I hope this can help you.

- 1
- 1

- 3,559
- 4
- 25
- 46
-
Thanks, this is really useful, especially for commands not supported by SSH.NET directly. – Erik May 18 '16 at 05:07