Can't get attributes of file '/'.
Hi,
I have written a Windows service that periodically checks the FTP for new files. When it finds a file, it FTPs the file to another server. The first time it found a file, I received this error:
Here is the method that I am using:
Thanks for your help.
I have written a Windows service that periodically checks the FTP for new files. When it finds a file, it FTPs the file to another server. The first time it found a file, I received this error:
I am attaching a log of the event.Message: Can't get attributes of file '/'.
Stack Trace: at WinSCP.OperationResultBase.Check()
Here is the method that I am using:
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); } }