Can't get attributes of file No such file or directory

Advertisement

tzpow2
Joined:
Posts:
3

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.
  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
            {
            }

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
28,802
Location:
Prague, Czechia

Re: Can't get attributes of file No such file or directory

This might be the problem:
thisfile = thisfile.ToUpper();
Use the file name as is, when calling session.GetFiles.

Reply with quote

Guest

Re: Can't get attributes of file No such file or directory

martin wrote:

This might be the problem:
thisfile = thisfile.ToUpper();
Use the file name as is, when calling session.GetFiles.

No, I tried removing that still getting the same error.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
28,802
Location:
Prague, Czechia

Re: Can't get attributes of file No such file or directory

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Reply with quote

Advertisement

tzpow2
Joined:
Posts:
3

Re: Can't get attributes of file No such file or directory

martin wrote:

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.


Hi the log is in the very first post. I am using version 5.7.6, and I can't upgrade it because the server that is running the Jobs is also the same version.

Thanks

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
28,802
Location:
Prague, Czechia

Re: Can't get attributes of file No such file or directory

tzpow2 wrote:

Hi the log is in the very first post.
That's a log with ToUpper, hence useless.

I am using version 5.7.6, and I can't upgrade it because the server that is running the Jobs is also the same version.
You should not rely on an installed version of WinSCP. Your application should deploy it's own copy of WinSCP binaries.
See https://winscp.net/eng/docs/library_install#installing

Reply with quote

Advertisement

You can post new topics in this forum