当前位置: 首页>>代码示例>>C#>>正文


C# SftpClient.Dispose方法代码示例

本文整理汇总了C#中Renci.SshNet.SftpClient.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# SftpClient.Dispose方法的具体用法?C# SftpClient.Dispose怎么用?C# SftpClient.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Renci.SshNet.SftpClient的用法示例。


在下文中一共展示了SftpClient.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Send

    // Use this for initialization
    public void Send()
    {
        string address = "10.211.55.4";
        string user = "parallels";
        string pass = "Austinv0me6fp8";
        //string cmd = "r2 '/home/parallels/Desktop/Bomb.ex_' -c 'aa;s section..text;afn main;e asm.lines=False;e asm.comments=False;e asm.calls=false;e asm.cmtflgrefs=false;e asm.cmtright=false;e asm.flags=false;e asm.function=false;e asm.functions=false;e asm.vars=false;e asm.xrefs=false;e asm.linesout=false;e asm.fcnlines=false;e asm.fcncalls=false;e asm.demangle=false;aa;s section..text;pdf>main.txt;exit' -q";
        string cmd = "r2 '/home/parallels/Desktop/Bomb.ex_' -c 'aa; s section..text; afn main; pdf @ main > main.txt' -q";
        string uploadfile = @"/Users/JonathanWatts/Desktop/Bomb.ex_";
        string uploadDirectory = "/home/parallels/Desktop/";
        //Upload a file to a linux VM
        using (var sftp = new SftpClient(address, user, pass))
        {
            try
            {
                sftp.Connect();
                using (var fileStream = new FileStream(uploadfile, FileMode.Open))
                {
                    Console.WriteLine("Uploading {0} ({1:N0} bytes)",
                                          uploadfile, fileStream.Length);
                    sftp.BufferSize = 4 * 1024; // bypass Payload error large files
                    sftp.UploadFile(fileStream, uploadDirectory + Path.GetFileName(uploadfile));
                }
                sftp.Disconnect();
                sftp.Dispose();
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        //This block of code will send linux terminal commands from windows machine to linux virtual machine
        using(SshClient client = new SshClient(address,user, pass))
        {
            try
            {
                Debug.Log ("Sending Command...");
                client.Connect();
                Debug.Log ("Sending Command...");
                var result = client.RunCommand(cmd);
                Debug.Log (result);
                client.Disconnect();
                Debug.Log ("Sending Command...");
                client.Dispose();
            }
            catch(Exception ex)
            {
                Debug.Log (ex.Message);
                Console.WriteLine(ex.Message);
            }
        }

        //This block of code will download the file from linux VM to the windows host machine
        try
        {
            Debug.Log ("Uploading file...");
            using (var sftp = new SftpClient(address, user, pass))
            {
                sftp.Connect();
                if(File.Exists("/Users/JonathanWatts/main333.txt"))
                {
                    File.Delete("/Users/JonathanWatts/main333.txt");
                }
                using (Stream file1 = File.OpenWrite("/Users/JonathanWatts/main333.txt"))
                {
                    try
                    {

                        sftp.DownloadFile("main.txt", file1);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    file1.Close();

                }
                sftp.Disconnect();
                sftp.Dispose();
            }
        }
        catch(Exception ex)
        {
            Debug.Log (ex.Message);
            Console.WriteLine(ex.Message);
        }

        //SshShell shell = new SshShell(address, user, pass);
    }
开发者ID:dannisliang,项目名称:malwarevis,代码行数:90,代码来源:Send_Command.cs

示例2: Main

        static void Main(string[] args)
        {
            string address = "192.168.17.129";
            string user = "swastik";
            string pass = "singh";
            string cmd = "r2 '/home/swastik/Desktop/Bomb.ex_' -c 'aa;s section..text;pdf;pdi;e asm.lines=False;e asm.comments=False;e asm.calls=false;e asm.cmtflgrefs=fal;e asm.cmtright=false;e asm.flags=false;e asm.function=false;e asm.functions=fals;e asm.vars=false;e asm.xrefs=false;e asm.linesout=false;e asm.fcnlines=false;e asm.fcncalls=false;e asm.demangle=false;aa;s section..text;pdf>main.txt;exit' -q";
            string uploadfile = @"C:\Users\Swastik\Google Drive\Research\Malaware Visualization\Tool\radare2-w32-0.9.9-git\Bomb.ex_";
            string uploadDirectory = "/home/swastik/Desktop/";
            //Upload a file to a linux VM
            using (var sftp = new SftpClient(address, user, pass))
            {
                try
                {
                    sftp.Connect();
                    using (var fileStream = new FileStream(uploadfile, FileMode.Open))
                    {
                        Console.WriteLine("Uploading {0} ({1:N0} bytes)",
                                            uploadfile, fileStream.Length);
                        sftp.BufferSize = 4 * 1024; // bypass Payload error large files
                        sftp.UploadFile(fileStream, uploadDirectory + Path.GetFileName(uploadfile));
                    }
                    sftp.Disconnect();
                    sftp.Dispose();
                }
                catch(Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            //This block of code will send linux terminal commands from windows machine to linux virtual machine
            using(SshClient client = new SshClient(address,user, pass))
            {
                try
                {
                    client.Connect();
                    var result = client.RunCommand(cmd);
                    client.Disconnect();
                    client.Dispose();
                }
                catch(Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            //This block of code will download the file from linux VM to the windows host machine
            try
            {
                using (var sftp = new SftpClient(address, user, pass))
                {
                    sftp.Connect();
                    using (Stream file1 = File.OpenWrite("d:\\main333.txt"))
                    {
                        try
                        {

                            sftp.DownloadFile("main.txt", file1);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        file1.Close();

                    }
                    sftp.Disconnect();
                    sftp.Dispose();
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            //SshShell shell = new SshShell(address, user, pass);
        }
开发者ID:dannisliang,项目名称:malwarevis,代码行数:77,代码来源:Program.cs


注:本文中的Renci.SshNet.SftpClient.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。