Beispiel #1
0
    // gets remote file size (in KiB)
    public long getFileSize(string remoteFilePath)
    {
        WinSCP.RemoteFileInfo rfi = this.getRemoteFileInfo(remoteFilePath);
        long sizeInKiB            = rfi.Length / 1024;

        return(sizeInKiB);
    }
 public void setCurrentTransferSrc(RemoteFileInfo srcFile)
 {
     currentTransfer = srcFile;
     currentTransferSrcPath = sourcePath + '/' + srcFile.Name;
     // Select expedition directory
     currentTransferDir = session.ListDirectory(currentTransferSrcPath);
 }
Beispiel #3
0
 public RemoteFileInfo(WinSCP.RemoteFileInfo _remoteFileInfo)
 {
     try
     {
         FilePermissions = _remoteFileInfo.FilePermissions;
         FileType        = _remoteFileInfo.FileType;
         Group           = _remoteFileInfo.Group;
         IsDirectory     = _remoteFileInfo.IsDirectory;
         LastWriteTime   = _remoteFileInfo.LastWriteTime;
         Length          = _remoteFileInfo.Length;
         Length32        = _remoteFileInfo.Length32;
         Name            = _remoteFileInfo.Name;
         Owner           = _remoteFileInfo.Owner;
     }
     catch (Exception e)
     {
         if (e.GetType() != typeof(OverflowException))
         {
             LOG.WarnFormat("Error: {0} : {1}", e.Message, e.StackTrace);
         }
     }
 }
Beispiel #4
0
 internal void AddFile(RemoteFileInfo file)
 {
     Files.InternalAdd(file);
 }
 internal void AddFile(RemoteFileInfo file)
 {
     Files.InternalAdd(file);
 }
Beispiel #6
0
        public RemoteDirectoryInfo ListDirectory(string path)
        {
            using (Logger.CreateCallstackAndLock())
            {
                CheckOpened();

                WriteCommand(string.Format(CultureInfo.InvariantCulture, "ls -- \"{0}\"", ArgumentEscape(IncludeTrailingSlash(path))));

                RemoteDirectoryInfo result = new RemoteDirectoryInfo();

                using (ElementLogReader groupReader = _reader.WaitForGroupAndCreateLogReader())
                using (ElementLogReader lsReader = groupReader.WaitForNonEmptyElementAndCreateLogReader("ls", LogReadFlags.ThrowFailures))
                {
                    if (lsReader.TryWaitForNonEmptyElement("files", 0))
                    {
                        using (ElementLogReader filesReader = lsReader.CreateLogReader())
                        {
                            while (filesReader.TryWaitForNonEmptyElement("file", 0))
                            {
                                RemoteFileInfo fileInfo = new RemoteFileInfo();

                                using (ElementLogReader fileReader = filesReader.CreateLogReader())
                                {
                                    while (fileReader.Read(0))
                                    {
                                        string value;
                                        if (fileReader.GetEmptyElementValue("filename", out value))
                                        {
                                            fileInfo.Name = value;
                                        }
                                        else
                                        {
                                            ReadFile(fileInfo, fileReader);
                                        }
                                    }

                                    result.AddFile(fileInfo);
                                }
                            }
                        }

                        groupReader.ReadToEnd(LogReadFlags.ThrowFailures);
                    }
                    else
                    {
                        // "files" not found, keep reading, we expect "failure"
                        groupReader.ReadToEnd(LogReadFlags.ThrowFailures);
                        // only if not "failure", throw "files" not found
                        throw SessionLocalException.CreateElementNotFound(this, "files");
                    }
                }

                return result;
            }
        }
Beispiel #7
0
 private void ReadFile(RemoteFileInfo fileInfo, CustomLogReader fileReader)
 {
     using (Logger.CreateCallstack())
     {
         string value;
         if (fileReader.GetEmptyElementValue("type", out value))
         {
             fileInfo.FileType = value[0];
         }
         else if (fileReader.GetEmptyElementValue("size", out value))
         {
             fileInfo.Length = long.Parse(value, CultureInfo.InvariantCulture);
         }
         else if (fileReader.GetEmptyElementValue("modification", out value))
         {
             fileInfo.LastWriteTime = XmlConvert.ToDateTime(value, XmlDateTimeSerializationMode.Local);
         }
         else if (fileReader.GetEmptyElementValue("permissions", out value))
         {
             fileInfo.FilePermissions = FilePermissions.CreateReadOnlyFromText(value);
         }
     }
 }
Beispiel #8
0
        private RemoteFileInfo DoGetFileInfo(string path)
        {
            using (Logger.CreateCallstack())
            {
                WriteCommand(string.Format(CultureInfo.InvariantCulture, "stat -- \"{0}\"", ArgumentEscape(path)));

                RemoteFileInfo fileInfo = new RemoteFileInfo();

                using (ElementLogReader groupReader = _reader.WaitForGroupAndCreateLogReader())
                using (ElementLogReader statReader = groupReader.WaitForNonEmptyElementAndCreateLogReader("stat", LogReadFlags.ThrowFailures))
                {
                    while (statReader.Read(0))
                    {
                        string value;
                        if (statReader.GetEmptyElementValue("filename", out value))
                        {
                            fileInfo.Name = value;
                        }
                        else if (statReader.IsNonEmptyElement("file"))
                        {
                            using (ElementLogReader fileReader = statReader.CreateLogReader())
                            {
                                while (fileReader.Read(0))
                                {
                                    ReadFile(fileInfo, fileReader);
                                }
                            }
                        }
                    }

                    groupReader.ReadToEnd(LogReadFlags.ThrowFailures);
                }

                return fileInfo;
            }
        }