public static void UploadingOuterNet()
        {
            if (Program.LockOuterNet)
            {
                return;
            }
            if (AssetOperation.isUploadingOuterNet)
            {
                FTPUtils.UseProxy = true;
                string root           = Program.ProjectRootPath;
                string gangsterRes000 = Program.VersionFolder;
                var    resourcePath   = root + "\\" + gangsterRes000 + "\\";

                Program.ConsoleLog("上传修改的资源到外网中...");

                if (Program.Gangster_0_0_0_Path != "")
                {
                    FTPUtils.UploadingFile(Program.Gangster_0_0_0_Path, MainUploading.OuterNetFTPRootPath + "/" + Program.Gangster0_0_0_res_json);
                }

                var list = AssetOperation.ListChangeFils;
                for (int i = 0; i < list.Count; i++)
                {
                    var path = list[i];
                    path = path.Replace('\\', '/');
                    var relatePath    = AssetOperation.GetRelatePath(path, root);
                    var targetFtpPath = MainUploading.OuterNetFTPRootPath + relatePath;
                    FTPUtils.UploadingFile(path, targetFtpPath);
                }
                Program.ConsoleLog("上传修改的资源外网完成");
                MainUploading.UploadingWebsources();
            }
        }
Esempio n. 2
0
 public static void MakeDir(string dirPath)
 {
     if (!FTPUtils.FtpDirExists(dirPath))
     {
         try {
             FtpWebRequest  ftp      = FTPUtils.GetRequest(dirPath, WebRequestMethods.Ftp.MakeDirectory);
             FtpWebResponse response = (FtpWebResponse)ftp.GetResponse();
             response.Close();
         }
         catch (Exception ex) {
             Console.WriteLine("创建文件失败,原因: " + ex.Message);
         }
     }
 }
        public static void Uploading(string resourcePath)
        {
            if (MainUploading.isUploading)
            {
                Console.WriteLine("上传中...");
                var list = FileCollector.ListResourceInfo;

                for (int i = 0; i < list.Count; i++)
                {
                    var item          = list[i];
                    var filePath      = resourcePath + item.filePath;
                    var targetFtpPath = MainUploading.FTPRootPath + "/" + item.filePath;

                    FTPUtils.UploadingFile(filePath, targetFtpPath);
                }
            }
        }
Esempio n. 4
0
        public static bool FtpDirExists(string dirPath)
        {
            FtpWebRequest  reqFtp = FTPUtils.GetRequest(dirPath, WebRequestMethods.Ftp.ListDirectory);
            FtpWebResponse resFtp = null;

            try {
                resFtp = (FtpWebResponse)reqFtp.GetResponse();
                FtpStatusCode code = resFtp.StatusCode;//OpeningData
                resFtp.Close();
                return(true);
            }
            catch {
                if (resFtp != null)
                {
                    resFtp.Close();
                }
                return(false);
            }
        }
Esempio n. 5
0
        //ftp://192.168.19.58/WebResource/resource  /assets/test/111.png
        public static void CheckDir(string filePath)
        {
            var ftpRoot = MainUploading.FTPRootPath;
            var fileUrl = filePath.Replace(ftpRoot, "");
            var dirs    = fileUrl.Split('/');
            var dirPath = ftpRoot;

            for (int i = 0; i < dirs.Length - 1; i++)
            {
                if (dirs[i] == "")
                {
                    FTPUtils.MakeDir(dirPath);
                }
                else
                {
                    dirPath = dirPath + "/" + dirs[i];
                    FTPUtils.MakeDir(dirPath);
                }
            }
        }
        public static void UploadingWebsources()
        {
            FTPUtils.UseProxy = true;
            string gangsterRes000 = Program.VersionFolder;

            Program.ConsoleLog("上传webresources到外网中...");

            string webresourcePath = Program.WebResourcePath + FTPUtils.WebResourceUploadingDir;
            var    files           = Directory.GetFiles(webresourcePath, "*.*", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                var path = file;
                path = path.Replace('\\', '/');
                var relatePath    = AssetOperation.GetRelatePath(path, webresourcePath);
                var targetFtpPath = MainUploading.OuterNetFTPRootPath + "/" + gangsterRes000 + "/" + FTPUtils.WebResourceUploadingDir + relatePath;
                FTPUtils.UploadingFile(path, targetFtpPath);
            }
            Program.ConsoleLog("上传webresources外网完成");
        }
Esempio n. 7
0
        public static void UploadingFile(string filePath, string ftpPath)
        {
            var      url      = ftpPath;
            FileInfo fileInfo = new FileInfo(filePath);
            var      username = FTPUtils.UserName;
            var      password = FTPUtils.Password;

            FTPUtils.CheckDir(ftpPath);

            FtpWebRequest reqFtp = FTPUtils.GetRequest(url, WebRequestMethods.Ftp.UploadFile, username, password);

            reqFtp.ContentLength = fileInfo.Length;

            //缓冲大小设置为2KB
            const int BufferSize = 2048;

            byte[] content = new byte[BufferSize];
            int    contentLen;
            bool   success = true;

            using (FileStream fs = fileInfo.OpenRead()) {
                try {
                    using (Stream rs = reqFtp.GetRequestStream()) {
                        contentLen = fs.Read(content, 0, BufferSize);
                        while (contentLen != 0)
                        {
                            rs.Write(content, 0, contentLen);
                            contentLen = fs.Read(content, 0, BufferSize);
                        }
                    }
                }
                catch (Exception ex) {
                    success = false;
                    Console.WriteLine(ex.Message);
                }
                finally {
                    Console.WriteLine(fileInfo.FullName + (success ? " 上传成功" : " 上传失败"));
                    reqFtp = null;
                }
            }
        }