Can't get attributes of file No such file or directory
Hi
I am using C# code to download a file from FTP server and I am getting the "Can't get attributes of file No such file or directory" error. But there is the file. I can download it using GUI. It is very strange, if the test file is in "ROOT" directory, it works, but not in the sub folder. Also the folder looks strange. It is like "Jade:/PROD/Outbound". Anyone have this issue before?
Here is my code.
I am using C# code to download a file from FTP server and I am getting the "Can't get attributes of file No such file or directory" error. But there is the file. I can download it using GUI. It is very strange, if the test file is in "ROOT" directory, it works, but not in the sub folder. Also the folder looks strange. It is like "Jade:/PROD/Outbound". Anyone have this issue before?
Here is my code.
string winscpPath = "C:\\Program Files (x86)\\WinSCP\\WinSCP.exe"; string username = "username"; string password = "abc123"; string ftpSite = "SFTP.abc123.com"; string localPath = @"\\191.26.25.22\JADE\DownloadFiles\"; // string remoteFTPDirectory = "/"; //****Works if test file in root**** string remoteFTPDirectory = "/PROD/Outbound"; string sshKey = "ssh-dss 1024 2e:e0:68:f0:a0:40:12s3d1f2123s1dfsdf"; Boolean winSCPLog = true; string winSCPLogPath = @"\\191.26.25.22\JADE\"; SessionOptions sessionOptions = new SessionOptions { //FtpSecure = FtpSecure.Implicit, //FtpMode = FtpMode.Active, //Timeout = new TimeSpan(0, 0, 120), //120 seconds Protocol = Protocol.Sftp, HostName = ftpSite, UserName = username, Password = password, PortNumber = 22, SshHostKeyFingerprint = sshKey // SshHostKeyFingerprint = sshKey for ssh }; try { using (Session session = new Session()) { // WinSCP .NET assembly must be in GAC to be used with SSIS, // set path to WinSCP.exe explicitly, if using non-default path. session.ExecutablePath = winscpPath; session.DisableVersionCheck = true; if (winSCPLog) { session.SessionLogPath = @winSCPLogPath + @"ftpLog.txt"; session.DebugLogPath = @winSCPLogPath + @"Ftpdebuglog.txt"; } session.Open(sessionOptions); RemoteDirectoryInfo rDirectory = session.ListDirectory(remoteFTPDirectory); string filename = ""; for (int i = 0; i < rDirectory.Files.Count; i++) { string thisfile; thisfile = rDirectory.Files[i].Name; thisfile = thisfile.ToUpper(); if (thisfile.Contains("TEST") == true) { // session.MoveFile(remoteFTPDirectory + "/" + thisfile, remoteFTPDirectory + "/" + thisfile + ".txt"); session.GetFiles(thisfile, localPath, true); filename = filename + thisfile + "\n"; } } session.Close(); } } finally { }