2

I am currently using C# and SSH.NET to upload files or folders to a Unix server. My problem is, that Unix is case-sensitive, whereas Windows is not, or at least not really. So I am having a problem if I copy a folder called "test", and another folder called "Test". The different case is no problem for Unix of course, but under Windows, when accessing the folder via Samba, I can see only the contents of one of them.

What I want to do is the following: If I upload a file or folder over sftp, but that file or folder already exists with another combination of upper- or lowercase, I want to rename the file to be copied to match the name already present.

Is there an easy and convenient way to do that? What I basically need is a case-insensitive check if a folder or parts of a folder already exist.

Bridge
  • 29,818
  • 9
  • 60
  • 82
Erik
  • 2,316
  • 9
  • 36
  • 58

1 Answers1

-2

You can use the Directory.GetFiles and Directory.GetDirectories methods to list all files/directories in a directory and and then do a case insensitive match in your code.

https://msdn.microsoft.com/en-us/library/wz42302f(v=vs.110).aspx

https://msdn.microsoft.com/en-us/library/c1sez4sc(v=vs.110).aspx

Bridge
  • 29,818
  • 9
  • 60
  • 82
CamW
  • 3,223
  • 24
  • 34
  • Thanks, but that will not help me, because I conly have access to that direcotry using sftp in my code. is it possible to do it using only methods from the renci.ssh.net Library? – Erik May 11 '16 at 04:28
  • Yes, you could use the ssh.net library. Have a look here for details on the methods to list out the directories and files http://stackoverflow.com/questions/13572889/sshnet-sftp-get-files-and-directories – CamW May 11 '16 at 05:09
  • 1
    I have already found that thread, thanks, but it is lacking a working example. I am still wondering why I have to implement the recursive part myself, this should be handled by the library. Does it really make sense if everybody implements an own recursive solution, and everybody has to filter out the potential bugs (IsFile, remove . and .., etc.)? – Erik May 11 '16 at 05:12
  • It may not provide an outright solution but it has all the info you need to solve it yourself. It does make sense that the library doesn't implement the recursive part since the recursive part is basically just a method which makes use of the library. It's your unique usage of the tool provided. Have a go using the info you have and if you get stuck, post another question with your code. – CamW May 11 '16 at 05:19