当前位置: 首页>>代码示例>>C#>>正文


C# FtpClient.Upload方法代码示例

本文整理汇总了C#中FtpClient.Upload方法的典型用法代码示例。如果您正苦于以下问题:C# FtpClient.Upload方法的具体用法?C# FtpClient.Upload怎么用?C# FtpClient.Upload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FtpClient的用法示例。


在下文中一共展示了FtpClient.Upload方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Process

        public override ProcessResult Process()
        {
            ProcessResult res = new ProcessResult();
            res.ErrorCode = 0;
            Bitmap bmp = null;
            Graphics graph = null;
            FtpClient ftpClient = null;
            try
            {
                bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
                graph = Graphics.FromImage(bmp);
                graph.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
                FileName = string.Format("zrzut_{0}-{1}-{2}_{3}.jpg", DateTime.Now.Year.ToString(), DateTime.Now.Month.ToString(), DateTime.Now.Day.ToString(), DateTime.Now.Ticks.ToString());
                bmp.Save(FileName, ImageFormat.Jpeg);
                     ftpClient = new FtpClient(FTPSettings.ServerAddress, FTPSettings.User, FTPSettings.Password);
                     ftpClient.ChangeDir(FTPSettings.Directory);
                ftpClient.Upload(FileName);
                System.IO.File.Delete(FileName);

            }
            catch (Exception exc)
            {
                res.ErrorCode = 5;
                res.ErrorDetails = exc.ToString();
            }
            finally
            {
                if (ftpClient != null)
                ftpClient.Close();
                if (graph != null)
                graph.Dispose();
                if (bmp != null)
                bmp.Dispose();
            }
            return res;
        }
开发者ID:macper,项目名称:MWRWebRemoter,代码行数:36,代码来源:MakeScreenshootTask.cs

示例2: UploadWork

        private void UploadWork()
        {
            //LogManager.showNotifaction("ereqrew");
            //string str1 = LogManager.getTimeString();
            //string str = LogManager.getTimeString() + Path.GetExtension("c:\\123\\345\\222\\12346.jpg");
            //str.Equals("");

            

            //启动时先查看当前目录下是否有未上传完成的文件
            if (Directory.Exists(System.Environment.CurrentDirectory + "\\Data\\"))
            {
                List<string> listUnUploadFiles = new List<string>();
                calcFileCountAndAdd(System.Environment.CurrentDirectory + "\\Data\\", listUnUploadFiles);
                FtpList.AddRange(listUnUploadFiles);
            }


            FtpClient ftpClient = new FtpClient(m_ftpSever, m_ftpUser, m_ftpPwd, 120, int.Parse(m_ftpPort), m_ftpBuffer);

            //for test
            //ftpClient.Upload(FtpList[0], true);//true,断点续传 使用工作站中的文件上传,防止U盘被拔掉
            //string remoteRanameFile1 = LogManager.getTimeStringFileExtension(FtpList[0]);
            //ftpClient.RenameFile(Path.GetFileName(FtpList[0]), remoteRanameFile1, true);//上传后立刻重命名 格式20120312100624_001

            while (threadRunFlag)
            {

                Thread.Sleep(1);
                for( int i = 0; i<FtpList.Count; i++)
                {

                    if (FtpList.Count <= 0 || !threadRunFlag)
                    {
                        Thread.Sleep(1000);
                        continue;
                    }

                    Thread.Sleep(1);

                    string localFileName = FtpList[i];

                    try
                    {
                        ftpClient.Login();

                        //ftpClient.Download("0218620121203103434.mp4", "123.mp4", true);//断点下载
                        //LogManager.WriteLog("正在上传文件: " + );
                        //ftpClient.Upload(@"E:\company\MD\自动上传软件\执法记录仪资料\mp4\0218620121203103434.mp4",true);//断点续传


                        //从接口获取文件FTP的上传路径
                        string interface_Ftp = m_interfaceStr + "?method=getFtpPath";
                        string interface_Upload = m_interfaceStr + "?method=uploadFile";
                        string responseText = "";
                        string removeDir = "";//服务器返回的FTP文件存放路径
                        string removeDir1 = "";
                        string removeFileName = "";//上传到FTP上的文件绝对路径 1/101/103/11.mp4
                        try
                        {
                            if (HttpWebResponseUtility.getFtpDirRequestStatusCode(interface_Ftp, m_WorkStationID, MDUsb.getPoliceIDFromFile(localFileName), m_AppCode, out removeDir1)
                            != System.Net.HttpStatusCode.OK)
                            {

                                //接口调用失败,停止下面的工作,直接退出
                                writeMsg("错误,路径接口调用失败,请检查系统设备配置、网络及服务器!");
                                continue;
                            }
                        }
                        catch (Exception ex)
                        {

                            writeMsg("错误,接口调用失败,请检查系统设备配置、网络及服务器!");
                            LogManager.WriteErrorLog(ex.Message);
                            continue;
                        }
                        
                        string[] list1 = removeDir1.Substring(removeDir1.LastIndexOf('\n') + 1).Split(';');
                        if (!list1[0].Equals("0"))
                        {
                            LogManager.showErrorMsg("错误," + list1[1]);
                            continue;
                        }

                        removeDir = list1[1];



                        //切换到服务器接口返回的工作目录                            
                        ftpClient.MakeDirs(removeDir);
                        //ftpClient.ChangeDir(removeDir);

                        //上传文件
                        writeMsg("正在上传文件: " + localFileName);
                        ftpClient.Upload(localFileName, true);//true,断点续传 使用工作站中的文件上传,防止U盘被拔掉
                        string remoteRanameFile = LogManager.getTimeStringFileExtension(localFileName);
                        ftpClient.RenameFile(Path.GetFileName(localFileName), remoteRanameFile, true);//上传后立刻重命名 格式20120312100624_001


                        //获得文件的播放时间
//.........这里部分代码省略.........
开发者ID:PuGuanyu,项目名称:MDWorkStation,代码行数:101,代码来源:Form1.cs

示例3: UploadPicture

        /// <summary>
        /// TODO - use FtpClient
        /// </summary>
        /// <param name="imagePath"></param>
        private void UploadPicture(string imagePath)
        {
            string FtpServer = ConfigurationSettings.AppSettings["FtpServer"];
            string FtpUserName = ConfigurationSettings.AppSettings["FtpUserName"];
            string FtpPassword = ConfigurationSettings.AppSettings["FtpPassword"];

            FtpClient ftp = new FtpClient(FtpServer, FtpUserName, FtpPassword);
            ftp.Login();
            ftp.Upload(imagePath);
            ftp.Close();
        }
开发者ID:naveedcs,项目名称:iSpy,代码行数:15,代码来源:iSpyDetector.cs

示例4: savestatbut_Click

        private void savestatbut_Click(object sender, RoutedEventArgs e)
        {
            DataSet ds = new DataSet();
            DataTable tabnew = new DataTable();
            try
            {
                var ftpClient = new FtpClient(helper.ftpaddr, helper.ftplogin, helper.ftppass);
                DataView dv = (DataView)stat_grid.ItemsSource;
                tabnew = dv.Table.Copy();
                ds.Tables.Add(tabnew);
                XmlTextWriter newXml = new XmlTextWriter("asidupd.xml", Encoding.UTF8);
                ds.WriteXml(newXml);
                newXml.Close();

                ftpClient.Upload("/asuw_st/asidupd.xml", File.ReadAllBytes("asidupd.xml"));
                Console.WriteLine();
                loadStats();
            }
            catch
            {
                MessageBox.Show("Ошибка сети, попытайтесь позже.");
            }
        }
开发者ID:Baykov,项目名称:asid_cafe,代码行数:23,代码来源:MainWindow.xaml.cs

示例5: CopyFileToFTP

 private ProcessResult CopyFileToFTP()
 {
     ProcessResult pr = new ProcessResult();
     FtpClient ftpClient = null;
     pr.ErrorCode = 3;
     try
     {
         if (!File.Exists(RequestedObjectPath))
         {
             pr.ErrorDetails = "Plik " + RequestedObjectPath + " nie istnieje";
             return pr;
         }
         ftpClient = new FtpClient(FTPSettings.ServerAddress, FTPSettings.User, FTPSettings.Password);
         ftpClient.ChangeDir(FTPSettings.Directory);
         ftpClient.Upload(RequestedObjectPath);
         pr.ErrorCode = 0;
     }
     catch (Exception exc)
     {
         pr.ErrorDetails = exc.ToString();
     }
     finally
     {
         try
         {
             if (ftpClient != null)
             {
                 ftpClient.Close();
             }
         }
         catch { }
     }
     return pr;
 }
开发者ID:macper,项目名称:MWRWebRemoter,代码行数:34,代码来源:FileManageTask.cs

示例6: UploadFiles

        private void UploadFiles(FtpClient ftpClient, string remoteDir) {
            if(!ftpClient.DirectoryExists(remoteDir))
                ftpClient.CreateDirectory(remoteDir);

            var fis = new FileInfo[FileCount];

            for(int i = 0; i < FileCount; i++) {
                string file = LocalFileHeader + i;

                if(!File.Exists(file))
                    fis[i] = CreateTestFile(LocalFileHeader + i, BufferSize * 1024 * (i + 1));
                else
                    fis[i] = new FileInfo(file);
            }

            for(int i = 0; i < FileCount; i++) {
                using(new OperationTimer("Upload File:" + fis[i].FullName))
                    ftpClient.Upload(fis[i], RemoteFileHeader + i).Should().Be.True();

                fis[i].Delete();
            }
        }
开发者ID:debop,项目名称:NFramework,代码行数:22,代码来源:FtpClientFixture.cs


注:本文中的FtpClient.Upload方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。