Topic "Can't get attributes of file '/'."

Author Message
codenat
[View user's profile]

Joined: 2015-03-23
Posts: 12
Location: Columbia, SC
Hi,
I have written a windows service that periodically checks the ftp for new files. When it finds a file, it ftp's the file to another server. The first time it found a file, I received this error:

Message: Can't get attributes of file '/'.
Stack Trace: at WinSCP.OperationResultBase.Check()

I am attaching a log of the event.

Here is the method that I am using:
Code:

        private void qtsTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            string localPath = @"U:\CLM";
            string remotePath = "/";

            MyProgram_eventLog.WriteEntry("Checking the " + remotePath + " with the qtsTimer: " + DateTime.Now.ToString(), EventLogEntryType.Information);

            FtpQTS(localPath, remotePath);
        }

        private void FtpQTS(string localPath, string remotePath)
        {
            ///<summary>The full path of the file on the FTP server.</summary>
            string remoteFile;

            try
            {
                // Setup session options
                SessionOptions sessionOptions = new SessionOptions
                {
                    Protocol = Protocol.Ftp,
                    HostName = "ftp.comany.com",
                    UserName = "ftpuser",
                    Password = "ftppass",
                    // If using Protocol.Sftp then you would add the following line
                    // SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
                };
                MyProgram_eventLog.WriteEntry("A connection to ftpuser on ftpserver has been made", EventLogEntryType.Information);

                using (Session session = new Session())
                {
                    //log session
                    session.SessionLogPath = @"U:\CLM\Logs\WinSCPLog.log";

                    // Connect
                    session.Open(sessionOptions);

                    RemoteDirectoryInfo remoteDirectory = session.ListDirectory(remotePath);

                    MyProgram_eventLog.WriteEntry("Checking " + remotePath + " on ftpuser ftpserver for new files", EventLogEntryType.Information);

                    foreach (RemoteFileInfo fileInfo in remoteDirectory.Files)
                    {
                        if (fileInfo.Name != "..")
                        {
                            remoteFile = remotePath + fileInfo.Name;
                            MyProgram_eventLog.WriteEntry("A new file has been found: " + fileInfo.Name, EventLogEntryType.Information);

                            // Download the file and throw on any error
                            session.GetFiles(remotePath, localPath).Check();
                            MyProgram_eventLog.WriteEntry("Download to " + localPath + " done", EventLogEntryType.Information);

                            // Remove the file
                            session.RemoveFiles(remoteFile);
                            MyProgram_eventLog.WriteEntry("Removed file: " + remoteFile, EventLogEntryType.Information);
                        }
                        else
                        {
                            MyProgram_eventLog.WriteEntry("Found " + fileInfo.Name + " which is not a new file", EventLogEntryType.Information);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MyProgram_eventLog.WriteEntry("There was a problem in FtpQTS(): " + ex.ToString(), EventLogEntryType.Error);
                EmailError(ref ex);
            }
        }


Thanks for your help.
WinSCPLog150407_118.log (6.02 KB) [Download]

Description: WinSCP Session Log

Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24991
Location: Prague, Czechia
There's no "Can't get attributes of file '/'." error in the log. Are you sure you have attached a correct log file? What it is a full call stack of the exception? Do you know what line of a code throws the exception?
codenat
[View user's profile]

Joined: 2015-03-23
Posts: 12
Location: Columbia, SC
prikryl wrote:
There's no "Can't get attributes of file '/'." error in the log. Are you sure you have attached a correct log file? What it is a full call stack of the exception? Do you know what line of a code throws the exception?


Sorry ... I must've gotten my logs confused. Attached is the log with the error.

Full error:
Message: Can't get attributes of file '/'.
Stack Trace:
at WinSCP.OperationResultBase.Check() at FTP_Check4Files.FTP_Check4Files.FtpQTS(String localPath, String remotePath)
WinSCPLog150407_1318.log (7.14 KB) [Download]

Description: (none)

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24991
Location: Prague, Czechia
It looks like a bug in the FTP server.
When WinSCP asks it for a details on the root folder (/), it responds with information on ftpuser folder.
It's likely because the FTP root is physically a path like /home/ftpuser.
But the FTP server should completely isolate the client from that, let only that this is a security flaw.
Do you know what FTP server software is that? So that I can report this to the vendor.

Anyway, you might be able to workaround this using:

SessionOptions.AddRawSettings("FtpUseMlsd", "1");

This sets Use MLSD command for directory listing option to Off.
https://winscp.net/eng/docs/ui_login_ftp
codenat
[View user's profile]

Joined: 2015-03-23
Posts: 12
Location: Columbia, SC
prikryl wrote:
It looks like a bug in the FTP server.
When WinSCP asks it for a details on the root folder (/), it responds with information on ftpuser folder.
It's likely because the FTP root is physically a path like /home/ftpuser.
But the FTP server should completely isolate the client from that, let only that this is a security flaw.
Do you know what FTP server software is that? So that I can report this to the vendor.


Thanks for your quick response! IPSwitch File Transfer WS_FTP Server is what it uses.

prikryl wrote:
Anyway, you might be able to workaround this using:

SessionOptions.AddRawSettings("FtpUseMlsd", "1");

This sets Use MLSD command for directory listing option to Off.
https://winscp.net/eng/docs/ui_login_ftp


As of 15.04.16, it ran again with the addition of the above line of code. Received a similar error once again and the file did not get transferred. I am attaching the log of today's try. Here is the error:
error wrote:
There was a problem in FtpQTS(): WinSCP.SessionRemoteException: Can't get attributes of file '/'. ---> WinSCP.SessionRemoteException: Could not retrieve file information Invalid number of arguments SIZE --- End of inner exception stack trace --- at WinSCP.OperationResultBase.Check() at FTP_Check4Files.FTP_Check4Files.FtpQTS(String localPath, String remotePath)
150416Log.log (7.77 KB) [Download]

Description: Log with error from today's run after adding the recommended

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24991
Location: Prague, Czechia
Thanks.
Actually my previous analysis was wrong.
It's a bug in WinSCP:
https://winscp.net/tracker/show_bug.cgi?id=1314

I'm sending you an email with a development version of WinSCP to address you have used to register on this forum.
codenat
[View user's profile]

Joined: 2015-03-23
Posts: 12
Location: Columbia, SC
Well, unfortunately, the new .dll and .exe didn't seem to work.
Attached is the log file.
150428_1205Log.log (7.2 KB) [Download]

Description: 12:05 attempt at FTPing a file.

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24991
Location: Prague, Czechia
Thanks. I'm sending you an email with a new development version.
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License