예제 #1
0
파일: Program.cs 프로젝트: rexyanglucky/uba
 static void Main(string[] args)
 {
     UBA.Ftp.Lib.ISftpHelper Helper = new SftpHelper("ubaservice.chinacloudapp.cn", "ubaservice", "Uba20150316");
     Stopwatch watch = new Stopwatch();
     watch.Start();
     if (Helper.Connect())
     {
         Console.WriteLine("connect");
         for (int i = 0; i < 1; i++)
         {
             if (Helper.Put(@"/usr/local/src/2015-03-15.txt", @"/home/ubaservice/" + i + ".txt"))
             {
                 Console.WriteLine(i);
             }
         }
     }
     Helper.Disconnect();
     watch.Stop();
     Console.WriteLine(watch.Elapsed);
     Console.ReadKey();
 }
예제 #2
0
        internal static void UploadFile( ServerModel destModel, Action<int, string> ShowMessage)
        {
            try
            {
                string baseFolder = destModel.SourceDirectory;
                string destDir = destModel.DestDirectory;
                var host = destModel.ServerHost;
                var userName = destModel.ServerUserName;
                var pwd = destModel.ServerPwd;

                if (Directory.Exists(baseFolder) || File.Exists(baseFolder))
                {
                    List<FileInfo> fileList = new List<FileInfo>();

                    UBA.Ftp.Lib.ISftpHelper helper = new SftpHelper(host, userName, pwd);
                    if (helper.Connect())
                    {
                        //创建destDir
                        CopyDir(destModel.SourceDirectory, destModel.DestDirectory, helper, ShowMessage);
                        Console.WriteLine(helper.Disconnect());
                    }
                    else
                    {
                        ShowMessage(0, "上传文件失败:无法连接服务器" + DateTime.Now);
                        UBA.Common.LogHelperNet.Info("上传文件失败:无法连接服务器" + DateTime.Now, null);
                        Console.WriteLine("connect failure");
                    }

                }
                else
                {
                    Console.WriteLine("请输入正确的文件夹");
                    ShowMessage(0, "请输入正确的文件夹");
                }
            }
            catch (Exception ex)
            {
                ShowMessage(0, "上传文件失败");
                UBA.Common.LogHelperNet.Info("上传文件失败:" + DateTime.Now, ex);
            }
        }
예제 #3
0
        public static void UploadFile(ServerModel destModel)
        {
            try
            {

                Console.WriteLine("上传文件开始");
                UBA.Common.LogHelperNet.Info("上传文件开始:", null);
                string baseFolder = destModel.SourceDirectory;
                string destDir = destModel.DestDirectory;
                var host = destModel.ServerHost;
                var userName = destModel.ServerUserName;
                var pwd = destModel.ServerPwd;

                if (Directory.Exists(baseFolder))
                {
                    List<FileInfo> fileList = new List<FileInfo>();
                    ListFiles(baseFolder, ref fileList);
                    //fileList = fileList.Where(m => m.Name.Contains(DateTime.Now.ToString("yyyy_MM_dd"))).ToList();
                    UBA.Ftp.Lib.ISftpHelper helper = new SftpHelper(host, userName, pwd);
                    if (helper.Connect())
                    {
                        //创建destDir
                        CopyDir(destModel.SourceDirectory, destModel.DestDirectory, helper);
                        //helper.Mkdir(destDir);
                        //foreach (var item in fileList)
                        //{

                        //    //string destPath = destDir.TrimEnd('/') + "/" + item.Directory.Name;
                        //    //helper.Mkdir(destDir, item.Directory.Name);

                        //    string destName = destDir + "/" + item.Name;

                        //    if (helper.Put(item.FullName, destName))
                        //    {
                        //        Console.WriteLine("上传文件成功:" + item.FullName);
                        //        UBA.Common.LogHelperNet.Info("上传文件成功:" + item.FullName, null);
                        //    }
                        //    else
                        //    {
                        //        UBA.Common.LogHelperNet.Info("上传文件失败:" + item.FullName, null);
                        //        Console.WriteLine("Upload Failure");

                        //    }
                        //}
                        Console.WriteLine(helper.Disconnect());
                    }
                    else
                    {
                        UBA.Common.LogHelperNet.Info("上传文件失败:无法连接服务器" + DateTime.Now, null);
                        Console.WriteLine("connect failure");
                    }

                }
                else
                {
                    Console.WriteLine("请输入正确的文件夹");
                }
            }
            catch (Exception ex)
            {
                UBA.Common.LogHelperNet.Info("上传文件失败:" + DateTime.Now, ex);
            }
            Console.WriteLine("上传文件结束");
        }
예제 #4
0
파일: Program.cs 프로젝트: rexyanglucky/uba
        private static void UploadFile(object state)
        {
            try
            {

                Console.WriteLine("上传文件开始");
                UBA.Common.LogHelperNet.Info("上传文件开始:", null);
                string baseFolder = System.Configuration.ConfigurationManager.AppSettings["FileDirectory"];
                string destDir = System.Configuration.ConfigurationManager.AppSettings["DestDirectory"];
                var host = System.Configuration.ConfigurationManager.AppSettings["ServerHost"];
                var userName = System.Configuration.ConfigurationManager.AppSettings["ServerUserName"];
                var pwd = System.Configuration.ConfigurationManager.AppSettings["ServerPwd"];

                if (Directory.Exists(baseFolder))
                {
                    List<FileInfo> fileList = new List<FileInfo>();
                    ListFiles(baseFolder, ref fileList);
                    fileList = fileList.Where(m => m.Name.Contains(DateTime.Now.ToString("yyyy_MM_dd"))).ToList();
                    UBA.Ftp.Lib.ISftpHelper helper = new SftpHelper(host, userName, pwd);
                    if (helper.Connect())
                    {
                        Console.WriteLine("connect");

                        foreach (var item in fileList)
                        {
                            string destPath = destDir.TrimEnd('/') + "/" + item.Directory.Name;
                            helper.Mkdir(destDir, item.Directory.Name);
                            string destName = destPath + "/" + item.Name;

                            if (helper.Put(item.FullName, destName))
                            {
                                Console.WriteLine("上传文件成功:" + item.FullName);
                                UBA.Common.LogHelperNet.Info("上传文件成功:" + item.FullName, null);
                            }
                            else
                            {
                                UBA.Common.LogHelperNet.Info("上传文件失败:" + item.FullName, null);
                                Console.WriteLine("Upload Failure");

                            }
                        }
                        Console.WriteLine(helper.Disconnect());
                    }
                    else
                    {
                        UBA.Common.LogHelperNet.Info("上传文件失败:无法连接服务器" + DateTime.Now, null);
                        Console.WriteLine("connect failure");
                    }

                }
                else
                {
                    Console.WriteLine("请输入正确的文件夹");
                }
            }
            catch (Exception ex)
            {
                UBA.Common.LogHelperNet.Info("上传文件失败:" + DateTime.Now, ex);
            }
            Console.WriteLine("上传文件结束");
        }
예제 #5
0
파일: Program.cs 프로젝트: rexyanglucky/uba
        private static bool Upload(string zipName, string baseFolder, string destName)
        {
            try
            {
                var host = System.Configuration.ConfigurationManager.AppSettings["ServerHost"];
                var userName = System.Configuration.ConfigurationManager.AppSettings["ServerUserName"];
                var pwd = System.Configuration.ConfigurationManager.AppSettings["ServerPwd"];
                //UBA.Ftp.Lib.ISftpHelper Helper = new SftpHelper("ubaservice.chinacloudapp.cn", "ubaservice", "Uba20150316");
                UBA.Ftp.Lib.ISftpHelper Helper = new SftpHelper(host, userName, pwd);

                if (Helper.Connect())
                {
                    Console.WriteLine("connect");
                    if (Helper.Put(Path.Combine(baseFolder, zipName), destName))
                    {
                        Common.LogHelperNet.Info("上传文件成功:" + zipName, null);
                        Console.WriteLine("Upload successful");
                        return true;

                    }
                    else
                    {
                        Common.LogHelperNet.Info("上传文件失败:" + zipName, null);
                        Console.WriteLine("Upload Failure");

                    }
                }
                else
                {
                    Common.LogHelperNet.Info("上传文件失败:无法连接服务器" + zipName, null);
                    Console.WriteLine("connect failure");
                }
                Console.WriteLine(Helper.Disconnect());
                return false;

            }
            catch
            {
                return false;
            }
        }