Some context for this issue, I have a VS project that I am running as a service on windows. The project tries to retrieve files from a network folder via \\192.168.97.1\images and then upload them to another server through sftp client connection.
The files I'm trying to retrieve via network folder is actually hosted on a linux machine but I can still access it through file explorer in windows just fine.
public void TransferFiles(){
...
static string path = "\\192.168.97.1\images";
string filename;
try{
using(var sftp = new SftpClient(host, port, username, password)){
sftp.Connect();
sftp.ChangeDirectory(destinationDirectory);
if(sftp.IsConnected){
foreach(string file in Directory.GetFiles(path){
filename = Path.GetFileName(file);
Stream stream = File.OpenRead(file);
sftp.UploadFile(stream, filename);
stream.Dispose();
}
}
}
}
catch(Exception e){
Logger.WriteLine("Exception Caught ", e.ToString());
}
}
The issue seems to be the Directory.GetFiles() function as it cannot access the images folder and is giving me the System.IO.IOException when it hits that line. But when I copy this exact path "\\192.168.97.1\images" to file explorer I can access the folder no problem.
I am writing any exceptions I get to another file through the Logger class so I know what's going on. This is the full error I am getting:
Exception Caught System.IO.IOException: The specified server cannot perform the requested operation
at System.IO.Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileSystemEnumerableIterator`1.CommonInit()
at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
at System.IO.Directory.GetFiles(String path)
at Project1.ServiceClass.TransferFiles()
I've tried playing with the format of the path itself, like giving it double back slashes as shown below, but its still giving me the same error
\\192.168.97.1\\images
Everyone has full permissions to this folder as well so I'm not sure what the issue is here. Any help on this would be greatly appreciated!