Пример #1
0
        private bool UploadCameraFile(string fileName, string inout, CHostConfig host)
        {
            fileName = Application.StartupPath + @"\datas\" + host.Key + @"\" + fileName;
            int destIndex = -1;

            for (var i = 0; i < Param.HostList.Count; i++)
            {
                if (Param.HostList[i].Key == host.Dest)
                {
                    destIndex = i;
                    break;
                }
            }
            if (destIndex < 0)
            {
                File.Delete(fileName);
                Log.WriteLine(string.Format("找不到目标主机地址"));
                return(false);
            }
            var helper = FTPFactory.CreateDestFtp(destIndex);

            if (helper == null)
            {
                File.Delete(fileName);
                Log.WriteLine(string.Format("找不到相关ftp配置,文件名:{0},出入库类型:{1}。", fileName, inout));
                return(false);
            }
            Log.WriteLine(string.Format("文件名称:{0},出入库类型:{1},目标ftp服务器:{2}。", fileName, inout, helper.FtpServerIP));
            var toFile = Application.StartupPath + @"\datas\" + host.Key + @"\notify.txt";

            if (File.Exists(toFile))
            {
                File.Delete(toFile);
            }

            File.Copy(fileName, toFile);
            bool flag = helper.Upload(toFile);

            if (!flag)
            {
                Thread.Sleep(500);
                flag = helper.Upload(toFile);
            }
            if (flag)
            {
                Log.WriteLine(string.Format("文件名称:{0},上传完毕。", fileName));
            }
            else
            {
                Log.WriteLine(string.Format("文件名称:{0},上传失败!", fileName));
            }
            //上传完毕,删除本地
            File.Delete(toFile);
            File.Delete(fileName);  // 先不进行删除
            // Move(fileName);  // 保存本地文件到具体目录

            return(true);
        }
Пример #2
0
        private void UploadDefault(int fileNo)
        {
            var helper = FTPFactory.CreateDestFtp(fileNo);

            if (helper == null)
            {
                return;
            }
            File.WriteAllText("notify.txt", Param.DEFAULT, Encoding.Default);
            bool flag = helper.Upload(@".\notify.txt");

            if (!flag)
            {
                Thread.Sleep(500);
                helper.Upload(@".\notify.txt");
            }
            //上传完毕,删除本地
            File.Delete("notify.txt");
        }
Пример #3
0
        private bool Upload(string fileName, string inout)
        {
            var helper = FTPFactory.CreateDestFtp(fileName, inout);
            var path   = Application.StartupPath + @"\datas\";

            if (helper == null)
            {
                File.Delete(fileName);
                Log.WriteLine(string.Format("找不到相关ftp配置,文件名:{0},出入库类型:{1}。", fileName, inout));
                return(false);
            }
            Log.WriteLine(string.Format("文件名称:{0},出入库类型:{1},目标ftp服务器:{2}。", fileName, inout, helper.FtpServerIP));
            if (File.Exists(path + "notify.txt"))
            {
                File.Delete(path + "notify.txt");
            }
            File.Copy(path + fileName, path + "notify.txt");
            bool flag = helper.Upload(path + "notify.txt");

            if (!flag)
            {
                Thread.Sleep(500);
                flag = helper.Upload(path + "notify.txt");
            }
            if (flag)
            {
                Log.WriteLine(string.Format("文件名称:{0},上传完毕。", fileName));
            }
            else
            {
                Log.WriteLine(string.Format("文件名称:{0},上传失败!", fileName));
            }
            //上传完毕,删除本地
            File.Delete(path + "notify.txt");
            File.Delete(path + fileName);  // 先不进行删除
            // Move(fileName);  // 保存本地文件到具体目录

            return(true);
        }