Exemplo n.º 1
0
        public void ftp_list_sub()
        {
            string strReturn = "";

            SecureTransfer.SSHTransferProtocol Protocol = SecureTransfer.SSHTransferProtocol.SFTP;

            try {
                st = new SecureTransfer(hosts, user, password,
                                        int.Parse(port), Protocol);

                st.Connect();

                switch (Protocol)
                {
                case SecureTransfer.SSHTransferProtocol.SFTP:
                    st.asyncCallback = AsyncCallback;
                    break;
                }

                strReturn = st.List_File(dir);
            } catch (Exception ex) {
                pFrmApp.JS_Function(this.callback_error, ex.ToString());
                st?.Disconnect();
                st?.Dispose();
            }

            pFrmApp.Call_Event(callback, strReturn);
        }
Exemplo n.º 2
0
        public void ftp_download(
            string hosts, string user,
            string password, string port,
            string source_file, string dest_file,
            string callback_status,
            string callback_error)
        {
            this.callback_status = callback_status;
            this.callback_error  = callback_error;
            SecureTransfer.SSHTransferProtocol Protocol = SecureTransfer.SSHTransferProtocol.SFTP;

            try {
                st = new SecureTransfer(hosts, user, password,
                                        int.Parse(port), Protocol,
                                        source_file, dest_file);

                st.Connect();

                switch (Protocol)
                {
                case SecureTransfer.SSHTransferProtocol.SFTP:
                    st.asyncCallback = AsyncCallback;
                    break;
                }

                var t = new Thread(Start_Download);
                t.SetApartmentState(ApartmentState.STA);
                t.IsBackground = true;
                t.Start();
            } catch (Exception ex) {
                pFrmApp.JS_Function(this.callback_error, ex.ToString());
                st?.Disconnect();
                st?.Dispose();
            }
        }
Exemplo n.º 3
0
        private void StartTransfer(SecureTransfer.SSHTransferProtocol Protocol)
        {
            if (AllFieldsSet() == false)
            {
                Runtime.MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg, Language.strPleaseFillAllFields);
                return;
            }

            if (File.Exists(txtLocalFile.Text) == false)
            {
                Runtime.MessageCollector.AddMessage(Messages.MessageClass.WarningMsg, Language.strLocalFileDoesNotExist);
                return;
            }

            try
            {
                st = new SecureTransfer(txtHost.Text, txtUser.Text, txtPassword.Text, int.Parse(txtPort.Text), Protocol, txtLocalFile.Text, txtRemoteFile.Text);

                // Connect creates the protocol objects and makes the initial connection.
                st.Connect();

                if (Protocol == SecureTransfer.SSHTransferProtocol.SCP)
                {
                    st.ScpClt.Uploading += ScpClt_Uploading;
                }

                if (Protocol == SecureTransfer.SSHTransferProtocol.SFTP)
                {
                    st.asyncCallback = AsyncCallback;
                }

                var t = new Thread(StartTransferBG);
                t.SetApartmentState(ApartmentState.STA);
                t.IsBackground = true;
                t.Start();
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddExceptionStackTrace(Language.strSSHTransferFailed, ex);
                st?.Disconnect();
                st?.Dispose();
            }
        }