Unity3d to the Linux server SCP file using C # via WINSCP command line

Source: Internet
Author: User
Tags scp file winscp command line

Encountering a requirement is to upload the generated assetbundle package to the resource server and Linux for the resource server when Unity3d does the editor tool.

The implementation is divided into three parts: 1,c# Upload Tool class; 2,WINSCP script; 3, the upload function is used for the parameter invocation.


1,c# Upload Tool class

using unityengine;using system.collections;using system.io;using system;using  System.diagnostics;public class uploadhelper{    public static void  calluploadprocess (string arguments)     {         string winscppath = directory.getparent (Application.datapath)  +  "/WinSCP/ WinSCP.exe ";        try         {            Process proc =  null;            bool redirectoutput =  false;            proc = new  Process ();             proc. startinfo.filename = winscppath;            proc. startinfo.arguments = arguments;             if  (redirectoutput)             {                 proc. startinfo.useshellexecute = false;                 proc. startinfo.redirectstandardoutput = true;                 proc. startinfo.createnowindow = true;             }            else             {          & nbSp;     proc. startinfo.createnowindow = false;             }            proc. Start ();            if  (redirectOutput)              {                 //Redirect, show upload tool output                  streamreader sr = proc. standardoutput;                 while  (!SR. Endofstream)                 {                   & NBsP; STRING S = SR. ReadLine ();                     unityengine.debug.log (s);                 }            }             proc. WaitForExit ();            if  (Proc. exitcode == 0)             {                  UnityEngine.Debug.LogFormat ("[{0}]  upload complete!",  datetime.now.tostring ("Yyyy-mm-dd hh:mm:ss"));             }             else            {                 unityengine.debug.logformat ("[{0}]  upload failed! exitcode:{1 } ",  datetime.now.tostring (" Yyyy-mm-dd hh:mm:ss "),  proc. ExitCode);            }         }        catch  (Exception ex)          {             unityengine.debug.logerror (String.Format ("Exception occurred :{0},{1}",  ex. Message, ex. Stacktrace.tostring ()));         }    }}

2,WINSCP script,

Uploadassetbundles.script
Option echo offoption Batch onoption confirm Offopen scp://"%1%": "%2%" @ "%3%" option transfer binarysynchronize Remote-mir Ror-delete%4%%5%chmod 755%5%/*closeexit

3,c# Program incoming call implementation upload function

Private static void uploadtoserver (Buildtarget target)     {         string remotefolder = null;//Remote Server resource path          switch  (target)         {             case  buildtarget.standalonewindows64:                 remoteFolder =  "###/assetbundle/pc";                 break;             case BuildTarget.Android:                 remoteFolder =  "###/assetbundle/android";                 break;            case  buildtarget.ios:                 remoteFolder =  "###/assetbundle/ios";                 break;             default:                 return;        }         string uploaderpath = application.datapath +  "/uploader";         //Script Path         string scriptpath =  uploaderPath +  "/uploadassetbundles.script";         // Log path    &NBSp;    string logpath = directory.getparent (Application.dataPath)  +   "/upload.log";        string localfolder =  application.datapath +  "/abs";//local Resource directory path         string[]  param ={                  "Test",//remote server login user name                   "test1234",//remote server login password                                    "192.168.1.xxx",//remote server IP or domain name                                   localfolder,                remotefolder,                 scriptPath,                 logPath,             };         String arguments = string.format ("/console /log={6} /script={5} /parameter  \ "{0}\"  \ "{1}\"  \ "{2}\"  \ "{3}\"  \ "{4}\" ",  param);         uploadhelper.calluploadprocess (arguments);     }

Arguments the last

/parameter \ "{0}\" \ "{1}\" \ "{2}\" \ "{3}\" \ "{4}\" "

Is the parameter passed to the WinSCP script, corresponding to "%1%" to "%5%" in the script.



About the WINSCP command line call description You can view the official website https://winscp.net/eng/docs/scripting.

WINSCP can be downloaded here: http://down.51cto.com/data/2304295.

This article is from the "zl1030 Records" blog, so be sure to keep this source http://zl1030.blog.51cto.com/274507/1920820

Unity3d to the Linux server SCP file using C # via WINSCP command line

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.