Проблема Ssh, как отправить большую команду?

etyipin

Client
Регистрация
15.12.2017
Сообщения
95
Благодарностей
35
Баллы
18
Есть код, который постит статью на вордпрес, привязывает к ней теги и картинки.
Код:
SshClient sshClient = new SshClient(project.Variables["ip"].Value, 22, project.Variables["login"].Value, project.Variables["pass"].Value);
sshClient.Connect();

IDictionary<Renci.SshNet.Common.TerminalModes, uint> termkvp = new Dictionary<Renci.SshNet.Common.TerminalModes, uint>();
            termkvp.Add(Renci.SshNet.Common.TerminalModes.ECHO, 53);
            ShellStream shellStream = sshClient.CreateShellStream("xterm", 80,24, 800, 600, 1024, termkvp);
       
shellStream.WriteLine("cd public_html");
shellStream.WriteLine("set +H");
string post = "POST_ID=\"$(wp post create --post_title=\""+
            project.Variables["origintitle"].Value+"\" --post_content=\""+
            project.Variables["post_text"].Value+"\" --post_status=publish --porcelain)\"";
project.SendInfoToLog(post);
shellStream.WriteLine(post);
           

if(project.Variables["en_genres"].Value != ""){   
    project.SendInfoToLog("Постим жанры");
    var tags = project.Variables["en_genres"].Value.Replace("|", " ");
    shellStream.WriteLine("wp post term add $POST_ID post_tag "+tags);
    shellStream.Expect(new Regex(@"Success:"), new TimeSpan(0, 1, 0));
}   

if(project.Variables["img"].Value != "" && project.Variables["img"].Value != @"imgs\noimg.jpg"){
    project.SendInfoToLog("Постим картинку");
    string str = project.Variables["img"].Value;
    str = str.Replace(@"\", "/");
   
    shellStream.WriteLine("wp media import --title=\"Watch online "+
    project.Variables["origintitle"].Value+"\" --alt=\"Watch online "+
    project.Variables["origintitle"].Value+"\" --featured_image "+
    str+" --post_id=$POST_ID");   
    shellStream.Expect(new Regex(@"Success:"), new TimeSpan(0, 2, 0));
}
shellStream.WriteLine("set -H");

sshClient.Disconnect();
Код всегда отрабатывает без зависаний и ошибок, но иногда картинка к статье не привязывается. Опытным путем вычислил, что дело в тексте (--post_content). То апостроф плохой, то знак валюты не нравится, то длинное тире и тд. Но при этом теже команды в PuTTY работают без проблем.
Пример команды:
Код:
POST_ID="$(wp post create --post_title="Wheely" --post_content="<h4>Watch Wheely Online HD! Free Streaming</h4><br/>[embed]https://www.youtube.com/watch?v=Izib4_Rwufg[/embed]<br/><strong>Watch the full video by the <a href=""#"" id=""watch"">link</a></strong><br/><br/><strong>Country: </strong>USA<br/><strong>Genre: </strong>Drama<br/><strong>Year: </strong><br/><br/><strong>Plot</strong><br/>On Coney Island in the 1950s, a lifeguard tells the story of a middle-aged carousel operator, his beleaguered wife, and the visitor who turns their lives upside-down.<br/><br/><a href=""#"" title=""Download Wheely"" id=""download""><img src=""/download.png"" width=""250px"" alt=""Download Wheely""/></a><br/><br/><strong>Related news about ""Wheely""</strong><br/>Where studio distributors have tentpole titles, specialized releasing has platform princes. These filmmakers are intellectual property: They will never produce blockbusters, at least not in the traditional sense, but their names trigger a passionate, arthouse fanbase eager to devour their work. And in the kingdom ruled by per-theater averages, Wes Anderson is the crown prince.Dozens of directors have found massive success with a platform release: Clint Eastwood, Darren Aronofsky, Jason Reitman, Tom Hooper, Steven Spielberg, the Coen Brothers, Richard Linklater, and Alejandro González Iñárritu. Other directors to achieve over USD100,000 per-theater averages in the last decade include Kevin Smith, Damian Chazelle, Morten Tyldum, Terence Malick, Lee Daniels, Luca Guadagnino, and Barry Jenkins. (Among watch any movie online free women, Kathryn Bigelow came closest with “Zero Dark Thirty.”)However, Anderson is among the few whose work consistently thrives not only in its initial limited release, but also expands to find a larger audience. That’s rare; in my film-buying days, Marvel’s groundbreaking film profits from the dearth of new releases, while renewed controversy for Woody Allen may have affected his latest Wonder WheelA commercially impotent set of new releases last Friday ensured that Black Panther remained unchallenged at the top of the UK box office for a fourth week, with weekend box office of £2.93m. After 27 days, watch movies online the title’s cumulative box office has reached £39.8m – ahead of the lifetime total of every Marvel film accept Avengers Assemble (£51.9m) and Avengers: Age of Ultron (£48.3m). Woody Allen’s Wonder Wheel struggles on debut.Rank Film / Distributor Weekend Gross (Fri-Sun) Running Total Week 1 Black Panther (Disney) £2.94m £39.83m 4 2 The Greatest Showman (Fox) £1.56m £37.33m 11 3 Red Sparrow (Fox) £1.17m £4.02m 2 4 Game Night (Warner) £886,000 £2.64m 2 5 Lady Bird (Universal) £697,130 £3.97m 3Today’s Gbp to Usd conversion rate watch recent movies online free - 1.39DisneyBlack Panther recorded a fourth straight week top of the UK box office, posting a strong hold by falling a slim 22% to £2.94m this weekend.The film is up to £39.83m, surpassing the UK total of Iron Man 3 (£36.97m) and Captain America: Civil War (£37m). By next weekend, the" --post_status=publish --porcelain)"
Предполагаю, что команду перед отправкой нужно как-то закодировать/экранировать, но как?
 
  • Спасибо
Реакции: bizzon

Radzhab

Client
Регистрация
23.05.2014
Сообщения
1 500
Благодарностей
1 268
Баллы
113
Это самый извращенный метод добавления постов в WP)
 
  • Спасибо
Реакции: backoff, Vass и kagorec

ol1ver

Client
Регистрация
29.08.2013
Сообщения
332
Благодарностей
82
Баллы
28

bizzon

Client
Регистрация
08.09.2015
Сообщения
1 103
Благодарностей
132
Баллы
63
///как-то закодировать/экранировать, но как?
тоже интересует...
 

etyipin

Client
Регистрация
15.12.2017
Сообщения
95
Благодарностей
35
Баллы
18

ol1ver

Client
Регистрация
29.08.2013
Сообщения
332
Благодарностей
82
Баллы
28

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)