示例#1
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);
            }
        }
示例#2
0
        public static void UploadFile(ServerModel model, Action<int, string> ShowMessage)
        {
            try
            {

                if (connectState(model.ServerHost, model.ServerUserName, model.ServerPwd))
                {
                    CopyDir(model.SourceDirectory, model.DestDirectory, ShowMessage);

                }
            }
            catch (Exception ee)
            {
                throw new Exception(ee.ToString());
            }
        }
示例#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("上传文件结束");
        }