private string BuildScript(WswrOp wOp, bool bTestOnly, string strTempFile,
            string strSessionUrl, string strRemoteDir, string strRemoteFile,
            string strHostKey)
        {
            StringBuilder sbScript = InitScript();

            string strOpen = AddCommonOpenOptions("open " + strSessionUrl,
                strSessionUrl);
            if(!string.IsNullOrEmpty(strHostKey))
                strOpen += " -hostkey=\"" + strHostKey + "\"";

            sbScript.AppendLine(strOpen);

            if(strRemoteDir.Length > 0)
                sbScript.AppendLine("cd \"" + strRemoteDir + "\"");

            if(bTestOnly)
            {
                if(wOp == WswrOp.Download)
                    sbScript.AppendLine("ls \"*" + strRemoteFile + "\"");
                else { Debug.Assert(false); }
            }
            else
            {
                if(wOp == WswrOp.Upload)
                    sbScript.AppendLine("put \"" + strTempFile + "\" \"" +
                        strRemoteFile + "\"");
                else if(wOp == WswrOp.Download)
                    sbScript.AppendLine("get \"" + strRemoteFile + "\" \"" +
                        strTempFile + "\"");
                else if(wOp == WswrOp.Delete)
                    sbScript.AppendLine("rm \"" + strRemoteFile + "\"");
                else if(wOp == WswrOp.Move)
                {
                    Uri uriTarget = new Uri(m_whcHeaders.Get(
                        IOConnection.WrhMoveFileTo));

                    sbScript.AppendLine("mv \"" + strRemoteFile + "\" \"" +
                        uriTarget.AbsolutePath + "\"");
                }
            }

            sbScript.AppendLine("exit");
            return sbScript.ToString();
        }
        private string BuildScript(WswrOp wOp, bool bTestOnly, string strTempFile,
                                   string strSessionUrl, string strRemotePath)
        {
            StringBuilder sbScript = InitScript();

            string strOpen = AddCommonOpenOptions("open " + strSessionUrl,
                                                  strSessionUrl);

            sbScript.AppendLine(strOpen);

            string strRemoteDir = UrlUtil.GetFileDirectory(strRemotePath,
                                                           false, false);
            string strRemoteFile = UrlUtil.GetFileName(strRemotePath);

            // For compatibility with KeePass < 2.28
            if (strRemoteDir == strRemotePath)
            {
                strRemoteDir = string.Empty;
            }

            // if(strRemoteDir.Length > 0)
            //	sbScript.AppendLine("cd \"" + strRemoteDir + "\"");

            if (bTestOnly)
            {
                if (wOp == WswrOp.Download)
                {
                    string strFilter = strRemoteDir;
                    if (strFilter.Length > 0)
                    {
                        strFilter += "/";
                    }
                    strFilter += "*" + strRemoteFile;
                    sbScript.AppendLine("ls \"" + strFilter + "\"");
                }
                else
                {
                    Debug.Assert(false);
                }
            }
            else
            {
                if (wOp == WswrOp.Upload)
                {
                    sbScript.AppendLine("put \"" + strTempFile + "\" \"" +
                                        strRemotePath + "\"");
                }
                else if (wOp == WswrOp.Download)
                {
                    sbScript.AppendLine("get \"" + strRemotePath + "\" \"" +
                                        strTempFile + "\"");
                }
                else if (wOp == WswrOp.Delete)
                {
                    sbScript.AppendLine("rm \"" + strRemotePath + "\"");
                }
                else if (wOp == WswrOp.Move)
                {
                    Uri uriTarget = new Uri(m_whcHeaders.Get(
                                                IOConnection.WrhMoveFileTo));
                    string strTarget = GetUriPath(uriTarget);

                    sbScript.AppendLine("mv \"" + strRemotePath + "\" \"" +
                                        strTarget + "\"");
                }
            }

            sbScript.AppendLine("exit");
            return(sbScript.ToString());
        }
        private string BuildScript(WswrOp wOp, bool bTestOnly, string strTempFile,
                                   string strSessionUrl, string strRemoteDir, string strRemoteFile,
                                   string strHostKey)
        {
            StringBuilder sbScript = InitScript();

            string strOpen = AddCommonOpenOptions("open " + strSessionUrl,
                                                  strSessionUrl);

            if (!string.IsNullOrEmpty(strHostKey))
            {
                strOpen += " -hostkey=\"" + strHostKey + "\"";
            }

            sbScript.AppendLine(strOpen);

            if (strRemoteDir.Length > 0)
            {
                sbScript.AppendLine("cd \"" + strRemoteDir + "\"");
            }

            if (bTestOnly)
            {
                if (wOp == WswrOp.Download)
                {
                    sbScript.AppendLine("ls \"*" + strRemoteFile + "\"");
                }
                else
                {
                    Debug.Assert(false);
                }
            }
            else
            {
                if (wOp == WswrOp.Upload)
                {
                    sbScript.AppendLine("put \"" + strTempFile + "\" \"" +
                                        strRemoteFile + "\"");
                }
                else if (wOp == WswrOp.Download)
                {
                    sbScript.AppendLine("get \"" + strRemoteFile + "\" \"" +
                                        strTempFile + "\"");
                }
                else if (wOp == WswrOp.Delete)
                {
                    sbScript.AppendLine("rm \"" + strRemoteFile + "\"");
                }
                else if (wOp == WswrOp.Move)
                {
                    Uri uriTarget = new Uri(m_whcHeaders.Get(
                                                IOConnection.WrhMoveFileTo));

                    sbScript.AppendLine("mv \"" + strRemoteFile + "\" \"" +
                                        uriTarget.AbsolutePath + "\"");
                }
            }

            sbScript.AppendLine("exit");
            return(sbScript.ToString());
        }