Example #1
0
        void doUpload(object sender, Renci.SshNet.Common.ShellDataEventArgs e)
        {
            var line = Encoding.UTF8.GetString(e.Data);
            var arr = line.Split(Environment.NewLine.ToCharArray()).Where(x => !string.IsNullOrEmpty(x)).ToList();

            //拿到路径之后开始上传
            var remoteBasePath = arr[1];

            using (var sftp = new SftpClient(server,port, user, pwd))
            {
                sftp.Connect();

                foreach (var file in fileList)
                {
                    string uploadfn = file;
                    var fileName = Path.GetFileName(file);
                    sftp.ChangeDirectory(remoteBasePath);
                    using (var uplfileStream = System.IO.File.OpenRead(uploadfn))
                    {
                        sftp.UploadFile(uplfileStream, fileName, true);
                    }

                    showLine(string.Format(" file===>{0}  uploaed", file));
                }
                sftp.Disconnect();
            }
            shellStream.DataReceived -= doUpload;
            shellStream.DataReceived += ShellStream_DataReceived;
        }
Example #2
0
 void auth2_AuthenticationPrompt(object sender, Renci.SshNet.Common.AuthenticationPromptEventArgs e)
 {
     foreach (var prompt in e.Prompts)
     {
         if (prompt.Request.Equals("Password: "******"Password" acquired from resource
         }
     }
 }
Example #3
0
 private static void Sftp_ErrorOccurred(object sender, Renci.SshNet.Common.ExceptionEventArgs e)
 {
     int m = 3;
 }
Example #4
0
        public static SSHSession AddToSSHSessionCollection(Renci.SshNet.SshClient sshclient, SessionState pssession)
        {
            //Set initial variables
            SSHSession obj = new SSHSession();
            List<SSHSession> SSHSessions = new List<SSHSession>();
            Int32 Index = 0;

            // Retrive existing sessions from the globla variable.
            var sessionvar = pssession.PSVariable.GetValue("Global:SshSessions") as List<SSHSession>;

            // If sessions exist  we set the proper index number for it.
            if (sessionvar != null)
            {
                SSHSessions.AddRange(sessionvar);
                Index = SSHSessions.Count;
            }

            // Create the object that will be saved
            obj.Index = Index;
            obj.Host = sshclient.ConnectionInfo.Host;
            obj.Session = sshclient;
            SSHSessions.Add(obj);

            // Set the Global Variable for the sessions.
            pssession.PSVariable.Set((new PSVariable("Global:SshSessions", SSHSessions, ScopedItemOptions.AllScope)));

            return obj;
        }
 private void conn_ErrorOccurred(object sender, Renci.SshNet.Common.ExceptionEventArgs e)
 {
     this.Close();
 }
Example #6
0
 public SftpDirectory(SftpStorage storage, SftpDirectory parent, Renci.SshNet.Sftp.SftpFile directory)
 {
     this.storage = storage;
     this.parent = parent;
     this.directory = directory;
 }
Example #7
0
        private void ScpClt_Uploading(object sender, Renci.SshNet.Common.ScpUploadEventArgs e)
        {
            // If the file size is over 2 gigs, convert to kb. This means we'll support a 2TB file.
            var max = e.Size > int.MaxValue ? Convert.ToInt32(e.Size / 1024) : Convert.ToInt32(e.Size);

            // yes, compare to size since that's the total/original file size
            var cur = e.Size > int.MaxValue ? Convert.ToInt32(e.Uploaded / 1024) : Convert.ToInt32(e.Uploaded);

            SshTransfer_Progress(cur, max);
        }
Example #8
0
        private void ShellStream_DataReceived(object sender, Renci.SshNet.Common.ShellDataEventArgs e)
        {
            var line = Encoding.UTF8.GetString(e.Data);

            showLine(line);
        }
Example #9
0
 void port_RequestReceived(object sender, Renci.SshNet.Common.PortForwardEventArgs e)
 {
     Log.WriteLine("Incoming forwarded connection from {0}:{1}",
         e.OriginatorHost, e.OriginatorPort);
 }
Example #10
0
 void port_Exception(object sender, Renci.SshNet.Common.ExceptionEventArgs e)
 {
     Log.WriteLine("Error in {0}: {1}", sender.GetType(), e.Exception.Message);
 }
Example #11
0
 void client_ErrorOccurred(object sender, Renci.SshNet.Common.ExceptionEventArgs e)
 {
     Log.WriteLine("SSh Session error: {0}", e.Exception.Message);
     MessageBox.Show(GetCaption("serverLoginError"), GetCaption("loginFailed"),
             MessageBoxButtons.OK, MessageBoxIcon.Warning);
 }
Example #12
0
 void stream_DataReceived(object sender, Renci.SshNet.Common.ShellDataEventArgs e)
 {
     var line = reader.ReadToEnd();
     while (line != null && !line.Equals(""))
     {
         bool x = line.Contains('\n');
         ToOutput(line);
         line = reader.ReadToEnd();
     }
 }
Example #13
0
 public SftpFile(SftpStorage storage, SftpDirectory parent, Renci.SshNet.Sftp.SftpFile file)
 {
     this.storage = storage;
     this.parent = parent;
     this.file = file;
 }
Example #14
0
 void ssh_ErrorOccurred(object sender, Renci.SshNet.Common.ExceptionEventArgs e)
 {
     //throw new Exception("SSH Error", e.Exception);
     Error(this, new ErrorArgs(e.Exception.Message));
 }