Beispiel #1
0
        private void expandSFTP(string path, TreeViewEventArgs e)
        {
            try
            {
                SftpGoToRoot();
                string fpath = sftproot + path;
                Log.Write(l.Debug, fpath);
                sftpc.cd(fpath);
                foreach (ChannelSftp.LsEntry lse in sftpc.ls("."))
                {
                    SftpATTRS attrs = lse.getAttrs();
                    if (lse.getFilename() != "." && lse.getFilename() != ".." && attrs.getPermissionsString().StartsWith("d"))
                    {
                        TreeNode ParentNode = new TreeNode();
                        ParentNode.Text = lse.getFilename();
                        e.Node.Nodes.Add(ParentNode);

                        TreeNode ChildNode = new TreeNode();
                        ChildNode.Text = lse.getFilename();
                        ParentNode.Nodes.Add(ChildNode);
                    }
                }
            }
            catch (Exception ex)
            {
                sftpc.quit();
                sftp_login();
                expandSFTP(path, e);
            }
        }
Beispiel #2
0
        public int SetFileAttributes(
            String filename,
            FileAttributes attr,
            DokanFileInfo info)
        {
            Debug("SetFileAttributes {0}", filename);
            try
            {
                string      path    = GetPath(filename);
                ChannelSftp channel = GetChannel();
                SftpATTRS   sattr   = channel.stat(path);

                int permissions = sattr.getPermissions();
                Debug(" permissons {0} {1}", permissions, sattr.getPermissionsString());
                sattr.setPERMISSIONS(permissions);
                channel.setStat(path, sattr);
                return(0);
            }
            catch (SftpException)
            {
                return(-1);
            }
            catch (Exception e)
            {
                connectionError_ = true;
                Debug(e.ToString());
                Reconnect();
                return(-1);
            }
        }
Beispiel #3
0
        private void fNewDir_Load(object sender, EventArgs e)
        {
            try
            {
                host      = ((frmMain)this.Tag).ftpHost();
                UN        = ((frmMain)this.Tag).ftpUser();
                pass      = ((frmMain)this.Tag).ftpPass();
                port      = ((frmMain)this.Tag).ftpPort();
                ftporsftp = ((frmMain)this.Tag).FTP();
                ftps      = ((frmMain)this.Tag).FTPS();
                ftpes     = ((frmMain)this.Tag).FTPES();
                ((frmMain)this.Tag).SetParent(host);

                if (ftporsftp)
                {
                    ftpc = new FtpClient(host, port);

                    if (ftps)
                    {
                        if (ftpes)
                        {
                            ftpc.SecurityProtocol = FtpSecurityProtocol.Tls1OrSsl3Explicit;
                        }
                        else
                        {
                            ftpc.SecurityProtocol = FtpSecurityProtocol.Tls1OrSsl3Implicit;
                        }
                        ftpc.ValidateServerCertificate += new EventHandler <ValidateServerCertificateEventArgs>(ftp_ValidateServerCertificate);
                    }

                    ftpc.Open(UN, pass);
                    Log.Write(l.Info, "Connected: " + ftpc.IsConnected.ToString());
                }
                else
                {
                    sftp_login();
                    sftproot = sftpc.pwd();
                }

                if (((frmMain)this.Tag).ftpParent() == "")
                {
                    tParent.Text = ((frmMain)this.Tag).ftpHost();
                }
                else
                {
                    tParent.Text = ((frmMain)this.Tag).ftpParent();
                }

                tPath.Text = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\FTPbox";

                Log.Write(l.Debug, ((frmMain)this.Tag).ftpParent() + " " + ((frmMain)this.Tag).ftpHost());

                treeView1.Nodes.Clear();

                TreeNode first = new TreeNode();
                first.Text = "/";
                treeView1.Nodes.Add(first);

                if (ftporsftp)
                {
                    foreach (FtpItem dir in ftpc.GetDirList())
                    {
                        if (dir.Name != "." && dir.Name != ".." && dir.ItemType == FtpItemType.Directory)
                        {
                            TreeNode ParentNode = new TreeNode();
                            ParentNode.Text = dir.Name;
                            treeView1.Nodes.Add(ParentNode);

                            TreeNode ChildNode = new TreeNode();
                            ChildNode.Text = dir.Name;
                            ParentNode.Nodes.Add(ChildNode);
                        }
                    }
                }
                else
                {
                    foreach (ChannelSftp.LsEntry lse in sftpc.ls("."))
                    {
                        SftpATTRS attrs = lse.getAttrs();
                        if (lse.getFilename() != "." && lse.getFilename() != ".." && attrs.getPermissionsString().StartsWith("d"))
                        {
                            TreeNode ParentNode = new TreeNode();
                            ParentNode.Text = lse.getFilename();
                            treeView1.Nodes.Add(ParentNode);

                            TreeNode ChildNode = new TreeNode();
                            ChildNode.Text = lse.getFilename();
                            ParentNode.Nodes.Add(ChildNode);
                        }
                    }
                }
                treeView1.SelectedNode = first;
                Set_Language(((frmMain)this.Tag).lang());
            }
            catch { this.Close(); }
        }