Ejemplo n.º 1
0
        protected override void WorkMethod()
        {
            string server = Settings.Default.ACMServer;
            int idx = server.IndexOf(':');
            if (idx != -1)
                server = server.Substring(0, idx);

            // upload file via FTP
            FTPLib.FTP ftp = new FTPLib.FTP(server, Settings.Default.ACMUsername, Settings.Default.ACMPassword);
            ftp.Connect();
            ftp.PassiveMode = Properties.Settings.Default.PassiveFTP;

            string xmlPath = CreateXML();
            UploadFile(ftp, xmlPath);
            UploadFile(ftp, m_path);
            File.Delete(xmlPath);

            ftp.Disconnect();

            /* <?xml version="1.0" encoding="UTF-8"?>
            <response status="fail">
              <error_code>INTERNAL_ERROR</error_code>
              <error_message>Internal server error parsing PBCore XML /media/psg/vol1/users/tightrope/TheKeyandthePortal-download.mpg.xml.</error_message>
            </response>
            */
            Scs.addContent(Path.GetFileName(m_path));
        }
Ejemplo n.º 2
0
        private int UploadXMLFiles(string fromLocalFolder, string toFTPServerFolder)
        {
            FTPLib.FTP    ftp    = new FTPLib.FTP();
            DirectoryInfo folder = new DirectoryInfo(fromLocalFolder);

            FileInfo[] fileList     = null;
            string     fileName     = "";
            string     fullFileName = "";
            var        count        = 0;

            while (true)
            {
                fileList = folder.GetFiles("*.xml");
                if (fileList.Count() == 0)
                {
                    break;
                }
                fileName      = fileList[0].Name;
                JinsPub.OrdID = fileName;
                fullFileName  = fileList[0].FullName;
                if (fullFileName.Length > 10)
                {
                    ftp.UploadFile(ftpServerIP, toFTPServerFolder, fullFileName, ftpUserID, ftpPassword);
                }
                File.Copy(Path.Combine(fromLocalFolder, fileName), Path.Combine(fromLocalFolder + @"\backup", fileName), true);
                fileList[0].Delete();
                count++;
            }
            return(count);
        }
Ejemplo n.º 3
0
        public int GetXMLFiles()
        {
            FTPLib.FTP ftp           = new FTPLib.FTP();
            string[]   fileList      = null;
            string     fileName      = "";
            int        countGetFiles = 0;

            while (true)
            {
                fileList = ftp.GetFileList(this.ftpServerIP, this.ftpServerFolder_order, this.ftpUserID, this.ftpPassword);
                if (null == fileList)
                {
                    break;
                }
                fileName      = fileList[0];
                JinsPub.OrdID = fileName.Substring(0, fileName.LastIndexOf("."));
                ftp.DownloadFile(this.ftpServerIP, this.ftpServerFolder_order, this.ftpUserID, this.ftpPassword, fileName, localFolder_order, fileName);
                File.Copy(Path.Combine(localFolder_order, fileName), Path.Combine(localFolder_order + @"\backup", fileName), true);
                try
                {
                    File.Copy(Path.Combine(localFolder_order, fileName), Path.Combine(localCopyFolder, fileName), true);
                }
                catch { }
                //var fullPath = localFolder_order + @"\" + fileName;
                //var model = Jinsxml.ConvertXMLtoOrdModel(fullPath);
                //Jinsdb.AddOrd(model);
                //FileInfo fi = new FileInfo(fullPath);
                //fi.Delete();
                ftp.DeleteFile(this.ftpServerIP, this.ftpServerFolder_order, fileName, this.ftpUserID, this.ftpPassword);
                countGetFiles++;
            }
            return(countGetFiles);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Determines the actual content length in a more reliable
        /// way for FTP downloads.
        /// </summary>
        /// <returns>-1 if no size could be determined</returns>
        private static long GetContentLength(WebResponse response)
        {
            HttpWebResponse http = response as HttpWebResponse;

            if (http != null)
            {
                return(http.ContentLength);
            }

            FtpWebResponse ftp = response as FtpWebResponse;

            if (ftp != null)
            {
                if (ftp.ContentLength > 0)
                {
                    return(ftp.ContentLength);
                }
                else
                {
                    // There is a problem with the .NET FTP implementation:
                    // "TYPE I" is never sent unless a file is requested, but is sometimes
                    // required by FTP servers to get the file size (otherwise error 550).
                    // Thus, we use a custom FTP library from code project for this task.
                    FTPLib.FTP ftpConnection = null;
                    try
                    {
                        ftpConnection = new FTPLib.FTP(response.ResponseUri.Host, "anonymous", "*****@*****.**");
                        return(ftpConnection.GetFileSize(response.ResponseUri.LocalPath));
                    }
                    catch (Exception)
                    {
                        // Limited trust in this code...
                        return(-1);
                    }
                    finally
                    {
                        if (ftpConnection != null)
                        {
                            ftpConnection.Disconnect();
                        }
                    }
                }
            }

            ScpWebResponse scp = response as ScpWebResponse;

            if (scp != null)
            {
                return(scp.ContentLength);
            }

            return(-1);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Determines the actual content length in a more reliable
        /// way for FTP downloads.
        /// </summary>
        /// <returns>-1 if no size could be determined</returns>
        private static long GetContentLength(WebResponse response)
        {
            HttpWebResponse http = response as HttpWebResponse;
            if (http != null)
            {
                return http.ContentLength;
            }

            FtpWebResponse ftp = response as FtpWebResponse;
            if (ftp != null)
            {
                if (ftp.ContentLength > 0)
                {
                    return ftp.ContentLength;
                }
                else
                {
                    // There is a problem with the .NET FTP implementation:
                    // "TYPE I" is never sent unless a file is requested, but is sometimes
                    // required by FTP servers to get the file size (otherwise error 550).
                    // Thus, we use a custom FTP library from code project for this task.
                    FTPLib.FTP ftpConnection = null;
                    try
                    {
                        ftpConnection = new FTPLib.FTP(response.ResponseUri.Host, "anonymous", "*****@*****.**");
                        return ftpConnection.GetFileSize(response.ResponseUri.LocalPath);
                    }
                    catch (Exception)
                    {
                        // Limited trust in this code...
                        return -1;
                    }
                    finally
                    {
                        if (ftpConnection != null) ftpConnection.Disconnect();
                    }
                }
            }

            ScpWebResponse scp = response as ScpWebResponse;
            if (scp != null)
            {
                return scp.ContentLength;
            }

            return -1;
        }