コード例 #1
0
        /// <summary>
        /// Instructs the remote server to go up one level
        /// </summary>
        /// <param name="server">A connected server I/O stream</param>
        protected void SCP_EnterIntoParent(Stream server)
        {
            try {
                byte[] tmp = new byte[1];

                // send "C0644 filesize filename", where filename should not include '/'

                string command = "E\n";
                if (Verbos)
                {
                    Console.WriteLine(command);
                }

                byte[] buff = StringAux.getBytes(command);
                server.Write(buff, 0, buff.Length);
                server.Flush();

                if (SCP_CheckAck(server) != 0)
                {
                    throw new SshTransferException("Error openning communication channel.");
                }
            }
            catch {
            }
        }
コード例 #2
0
        internal static string[] split(string foo, string split)
        {
            byte[] buf = StringAux.getBytes(foo);
            System.Collections.ArrayList bar = new System.Collections.ArrayList();
            int start = 0;
            int index;

            while (true)
            {
                index = foo.IndexOf(split, start);
                if (index >= 0)
                {
                    bar.Add(StringAux.getString(buf, start, index - start));
                    start = index + 1;
                    continue;
                }
                bar.Add(StringAux.getString(buf, start, buf.Length - start));
                break;
            }
            string[] result = new string[bar.Count];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = (string)(bar[i]);
            }
            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Transfer a file to the remote server
        /// </summary>
        /// <param name="server">A connected server I/O stream</param>
        /// <param name="src">The source file to copy</param>
        /// <param name="dst">The remote destination path</param>
        protected void SCP_SendFile(Stream server, string src, string dst)
        {
            int filesize = 0;
            int copied   = 0;

            filesize = (int)(new FileInfo(src)).Length;

            byte[] tmp = new byte[1];

            // send "C0644 filesize filename", where filename should not include '/'

            string command = "C0644 " + filesize + " " + Path.GetFileName(dst) + "\n";

            if (Verbos)
            {
                Console.WriteLine("Sending file modes: " + command);
            }
            SendStartMessage(src, dst, filesize, "Starting transfer.");
            byte[] buff = StringAux.getBytes(command);
            server.Write(buff, 0, buff.Length);
            server.Flush();

            if (SCP_CheckAck(server) != 0)
            {
                throw new SshTransferException("Error openning communication channel.");
            }

            // send a content of lfile
            SendProgressMessage(src, dst, copied, filesize, "Transferring...");
            FileStream fis = File.OpenRead(src);

            byte[] buf = new byte[1024 * 10 * 2];

            while (!m_cancelled)
            {
                int len = fis.Read(buf, 0, buf.Length);
                if (len <= 0)
                {
                    break;
                }
                server.Write(buf, 0, len);
                server.Flush();
                copied += len;
                SendProgressMessage(src, dst, copied, filesize, "Transferring...");
            }
            fis.Close();

            if (m_cancelled)
            {
                return;
            }

            // send '\0'
            buf[0] = 0;
            server.Write(buf, 0, 1);
            server.Flush();

            SendProgressMessage(src, dst, copied, filesize, "Verifying transfer...");
            if (SCP_CheckAck(server) != 0)
            {
                SendEndMessage(src, dst, copied, filesize, "Transfer ended with an error.");
                throw new SshTransferException("Unknow error during file transfer.");
            }
            SendEndMessage(src, dst, copied, filesize, "Transfer completed successfuly (" + copied + " bytes).");
        }