示例#1
0
        private void Start_Download()
        {
            try {
                st.Download();

                if (st.Protocol == SecureTransfer.SSHTransferProtocol.SFTP)
                {
                    SftpFileAttributes att = st.SftpClt.GetAttributes(st.SrcFile);
                    var fileSize           = att.Size;

                    while (!st.async_download_result.IsCompleted)
                    {
                        var max = fileSize > int.MaxValue
                            ? Convert.ToInt32(fileSize / 1024)
                            : Convert.ToInt32(fileSize);

                        var cur = fileSize > int.MaxValue
                            ? Convert.ToInt32(st.async_download_result.DownloadedBytes / 1024)
                            : Convert.ToInt32(st.async_download_result.DownloadedBytes);
                        Show_Progress(cur, max);
                        Thread.Sleep(100);
                    }
                }
                st.End_Download();
                pFrmApp.JS_Function(this.callback_error, "传输完毕");
                st.Disconnect();
                st.Dispose();
            } catch (Exception ex) {
                pFrmApp.JS_Function(this.callback_error, ex.ToString());
                st?.Disconnect();
                st?.Dispose();
            }
        }
示例#2
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);
        }
示例#3
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();
            }
        }