コード例 #1
0
 /// <summary>
 /// Copies a file from a remote SSH machine to the local machine using SCP.
 /// </summary>
 /// <param name="remoteFile">The remmote file name.</param>
 /// <param name="localPath">The local destination path.</param>
 /// <param name="recursive">Indicating whether a recursive transfer should take place.</param>
 public void From(string remoteFile, string localPath, bool recursive = false)
 {
     if (_scp.Connected)
     {
         // Receive the data.
         _scp.From(remoteFile, localPath, recursive);
     }
     else
     {
         throw new Exception("An active connection does not exist.");
     }
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: wyg031113/myvsproject
        static void testScp()
        {
            Scp s = new Scp("192.168.0.3", "root", "123456");

            s.Connect();


            if (s.Connected)
            {
                Console.WriteLine("connect server success");
                s.From("/root/hello.txt", "D:\\");
            }
        }
コード例 #3
0
        public void auxTransfer(RaspberryPi pi, string local, string remote)
        {
            Scp scp = new Scp(pi.getHostname(), pi.getUser(), pi.getPassword());

            try
            {
                scp.Connect();
                scp.From(remote, local);
                scp.Close();
            }

            catch (Exception)
            { }
        }
コード例 #4
0
        /// <summary>
        /// Demonstrates the Scp class
        /// </summary>
        /// <param name="cmd">Either "to" or "from"</param>
        public static void Scp(string cmd)
        {
            GetInput();

            string local = null, remote = null;

            if (cmd.ToLower().Equals("to"))
            {
                Console.Write("Local file: ");
                local = Console.ReadLine();
                Console.Write("Remote file: ");
                remote = Console.ReadLine();
            }
            else if (cmd.ToLower().Equals("from"))
            {
                Console.Write("Remote file: ");
                remote = Console.ReadLine();
                Console.Write("Local file: ");
                local = Console.ReadLine();
            }

            Scp scp = new Scp();

            scp.OnConnecting += new FileTansferEvent(scp_OnConnecting);
            scp.OnStart      += new FileTansferEvent(scp_OnProgress);
            scp.OnEnd        += new FileTansferEvent(scp_OnEnd);
            scp.OnProgress   += new FileTansferEvent(scp_OnProgress);

            try
            {
                if (cmd.ToLower().Equals("to"))
                {
                    scp.To(local, host, remote, user, pass);
                }
                else if (cmd.ToLower().Equals("from"))
                {
                    scp.From(host, remote, user, pass, local);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
コード例 #5
0
        public static void TransferFileFromMachine(string remoteFile, string localPath)
        {
            try
            {
                //Create a new SCP instance
                Scp scp = new Scp(MACHINE_IP, USER_NAME, PASSWORD);

                scp.Connect();

                //Copy a file from remote SSH server to local machine
                scp.From(remoteFile, localPath);

                scp.Close();
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #6
0
ファイル: Conect.cs プロジェクト: elkin5/test-csharp
        public static void BajarSCP(string pServidor, string pUsuario, string pPassword, string pFileRemoto, string pFileLocal)
        {
            // instancia del objeto SCP
            Scp SCP = new Scp(pServidor, pUsuario, pPassword);

            try
            {
                // crear conexion SSH
                SCP.Connect();
                // Bajar el archivo
                SCP.From(pFileRemoto, pFileLocal, false);
            }
            catch (Exception ex)
            { throw ex; }
            finally
            {
                //cerrar conexion SCP
                SCP.Close();
            } // end try
        }     // end BajarSCP