コード例 #1
0
ファイル: SftpForm.cs プロジェクト: sy26856/AMShell
        private bool RemoteExist(string path, string name, bool isdir = false)
        {
            string    dir       = path.Substring(0, path.Length - name.Length);
            ArrayList filesList = rightForm.getDirFiles(dir);

            if (null != filesList)
            {
                Tamir.SharpSsh.jsch.ChannelSftp.LsEntry entry = null;
                foreach (Object obj in filesList)
                {
                    if (obj is Tamir.SharpSsh.jsch.ChannelSftp.LsEntry)
                    {
                        entry = (Tamir.SharpSsh.jsch.ChannelSftp.LsEntry)obj;
                        if (entry.getFilename() == name)
                        {
                            if (isdir)
                            {
                                return(entry.getAttrs().isDir());
                            }
                            else
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
コード例 #2
0
ファイル: SftpForm.cs プロジェクト: sy26856/AMShell
        private void ParseDirEntryToQueue(string local, string remote, Tamir.SharpSsh.jsch.ChannelSftp.LsEntry dirs)
        {
            remote = remote + dirs.getFilename() + "/";
            local  = local + dirs.getFilename() + "/";
            ArrayList filesList = rightForm.getDirFiles(remote);

            Tamir.SharpSsh.jsch.ChannelSftp.LsEntry entry = null;
            foreach (var obj in filesList)
            {
                if (obj is Tamir.SharpSsh.jsch.ChannelSftp.LsEntry)
                {
                    entry = (Tamir.SharpSsh.jsch.ChannelSftp.LsEntry)obj;
                    if (entry.getAttrs().isDir())
                    {
                        if (!Utils.isLinuxRootPath(entry.getFilename()))
                        {
                            ParseDirEntryToQueue(local, remote, entry);
                        }
                    }
                    else
                    {
                        ParseEntryToQueue(local, remote, entry);
                    }
                }
            }
        }
コード例 #3
0
ファイル: SftpForm.cs プロジェクト: sy26856/AMShell
        public void TransferFilesToLocal(List <Object> filesList)
        {
            //ChannelSftp.LsEntry  getDirFiles
            string local  = leftForm.getCurrDir();
            string remote = rightForm.getCurrDir();

            Tamir.SharpSsh.jsch.ChannelSftp.LsEntry entry = null;
            foreach (Object obj in filesList)
            {
                if (obj is Tamir.SharpSsh.jsch.ChannelSftp.LsEntry)
                {
                    entry = (Tamir.SharpSsh.jsch.ChannelSftp.LsEntry)obj;
                    if (entry.getAttrs().isDir())
                    {
                        ParseDirEntryToQueue(local, remote, entry);
                    }
                    else
                    {
                        ParseEntryToQueue(local, remote, entry);
                    }
                }
            }

            StartR2L();
        }
コード例 #4
0
        public FtpFile(Tamir.SharpSsh.jsch.ChannelSftp.LsEntry fileInfo)
        {
            _fileName = fileInfo.getFilename();
            _filePath = fileInfo.getLongname();
            _size     = fileInfo.getAttrs().getSize();

            _creationDate  = DateTime.Parse(fileInfo.getAttrs().getMtimeString());
            _lastAcessTime = DateTime.Parse(fileInfo.getAttrs().getAtimeString());
            _lastWriteTime = _lastAcessTime;
        }
コード例 #5
0
ファイル: SftpForm.cs プロジェクト: sy26856/AMShell
        private void ParseEntryToQueue(string local, string remote, Tamir.SharpSsh.jsch.ChannelSftp.LsEntry file)
        {
            TransferItem item = new TransferItem();

            item.Id         = "R2L" + (idnum++);
            item.Name       = file.getFilename();
            item.LocalPath  = local + file.getFilename();
            item.RemotePath = remote + file.getFilename();
            item.Status     = TransferStatus.Wait;
            item.Size       = Utils.getFileSize(file.getAttrs().getSize());
            item.Progress   = 0;
            item.Speed      = "0 kb/s";

            AddItemToListView(item);
            remoteQueue.Enqueue(item);
        }
コード例 #6
0
ファイル: Sftp.cs プロジェクト: zevanreg/BizTalk-Sftp-Adapter
        /// <summary>
        /// This method is no longer used, but is left beacuase it might be used in the future.
        /// Developed to create a more efficient directory listing. By creating a random order of files,
        /// listing large amount of files from different different BizTalk nodes became more efficient.
        /// </summary>
        /// <param name="fileMask"></param>
        /// <param name="uri"></param>
        /// <param name="maxNumberOfFiles"></param>
        /// <param name="filesInProcess"></param>
        /// <param name="trace"></param>
        /// <returns></returns>
        private List <FileEntry> randomDir(string fileMask, string uri, int maxNumberOfFiles, ArrayList filesInProcess, bool trace)
        {
            List <FileEntry> fileEntries     = new List <FileEntry>();
            ArrayList        checkedOutFiles = new ArrayList();
            string           remotePath      = string.Empty;
            long             size;
            bool             isDirectory = false;
            string           fileName    = string.Empty;
            DateTime         fileLastWriten;
            int      index;
            TimeSpan ts;

            try
            {
                Tamir.SharpSsh.java.util.Vector entries = _sftp.Dir2(fileMask);

                System.Random autoRand = new System.Random();

                while (entries.Count > 0 && (fileEntries.Count < maxNumberOfFiles || maxNumberOfFiles == 0))
                {
                    index = autoRand.Next(entries.Count - 1);
                    Tamir.SharpSsh.jsch.ChannelSftp.LsEntry entry = (Tamir.SharpSsh.jsch.ChannelSftp.LsEntry)entries[index];

                    remotePath  = Path.GetDirectoryName(fileMask);
                    size        = entry.getAttrs().getSize();
                    isDirectory = entry.getAttrs().isDir();
                    fileName    = entry.getFilename();

                    if (isDirectory)
                    {
                        entries.RemoveAt(index);
                        continue;
                    }

                    try
                    {
                        fileLastWriten = DateTime.Parse(entry.getAttrs().getMtimeString());
                    }
                    catch { fileLastWriten = DateTime.Now.AddMinutes(1); }
                    ts = DateTime.Now.Subtract(fileLastWriten);

                    try
                    {
                        if (ts.TotalSeconds > TOTALTIMEDIFF &&
                            !filesInProcess.Contains(CommonFunctions.CombinePath(remotePath, fileName)))
                        {
                            // "Check out" file if UseLoadBalancing == true
                            if (uri != null && !DataBaseHelper.CheckOutFile(uri, System.Environment.MachineName, fileName, trace))
                            {
                                entries.RemoveAt(index);
                                continue;
                            }
                            else
                            {
                                // Check that file still exists
                                string filePath = fileMask.Substring(0, fileMask.LastIndexOf("/") + 1) + fileName;
                                if (_sftp.Exists(filePath))
                                {
                                    fileEntries.Add(new FileEntry(fileName, size));
                                }
                                else
                                {
                                    if (uri != null)
                                    {
                                        DataBaseHelper.CheckInFile(uri, fileName, trace);
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                        if (uri != null)
                        {
                            DataBaseHelper.CheckInFile(uri, fileName, trace);
                        }
                    }
                    entries.RemoveAt(index);
                }

                Trace.WriteLine(string.Format("[SftpReceiverEndpoint] Found {0} files.", fileEntries.Count));
                return(fileEntries);
            }
            catch (Exception ex)
            {
                throw new SftpException("Unable to perform directory list", ex);
            }
            finally
            {
                RaiseOnDisconnect();
            }
        }