Пример #1
0
        public static void RunExample()
        {
            try
            {
                SshConnectionInfo input = Util.GetInput();
                string proto = GetProtocol();
                SshTransferProtocolBase sshCp;

                if (proto.Equals("scp"))
                    sshCp = new Scp(input.Host, input.User);
                else
                    sshCp = new Sftp(input.Host, input.User);

                if (input.Pass != null)
                    sshCp.Password = input.Pass;
                if (input.IdentityFile != null)
                    sshCp.AddIdentityFile(input.IdentityFile);

                Console.Write("Connecting...");
                sshCp.Connect();
                Console.WriteLine("OK");

                while (true)
                {
                    string direction = GetTransferDirection();
                    if (direction.Equals("to"))
                    {
                        string lfile = GetArg("Enter local file ['Enter to cancel']");
                        if (lfile == "")
                            break;
                        string rfile = GetArg("Enter remote file ['Enter to cancel']");
                        if (rfile == "")
                            break;
                        sshCp.Put(lfile, rfile);
                    }
                    else
                    {
                        string rfile = GetArg("Enter remote file ['Enter to cancel']");
                        if (rfile == "")
                            break;
                        string lpath = GetArg("Enter local path ['Enter to cancel']");
                        if (lpath == "")
                            break;
                        sshCp.Get(rfile, lpath);
                    }
                }

                Console.Write("Disconnecting...");
                sshCp.Close();
                Console.WriteLine("OK");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Пример #2
0
        public static void RunExampleDownload()
        {
            try
            {
                SshTransferProtocolBase sshCp = new Sftp("host", "login", "password");
                Console.Write("Connecting...");
                sshCp.Connect();
                Console.WriteLine("OK");

                sshCp.Get("remote_file", "local_file");

                Console.Write("Disconnecting...");
                sshCp.Close();
                Console.WriteLine("OK");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Пример #3
0
 public MyProgressMonitor(Sftp sftp)
 {
     m_sftp = sftp;
 }