示例#1
0
        public async void ConnectAndGetLatest()
        {
            ftp.UnlockComponent("test");

            ftp.Hostname = "ftp.bodirectors.com";
            ftp.Username = Email + "@bodirectors.com";
            ftp.Password = Password;



            OutputFile = await ApplicationData.Current.LocalFolder.GetFileAsync("OutputNames.xml");

            SettingsFile = await ApplicationData.Current.LocalFolder.GetFileAsync("SettingsData.xml");

            ProfilePictureFile = await ApplicationData.Current.LocalFolder.GetFileAsync("profile.jpg");


            isFileDownloaded = await ftp.ConnectAsync();

            isFileDownloaded = await ftp.GetFileAsync("OutputNames.xml", OutputFile.Path);

            isFileDownloaded = await ftp.GetFileAsync("SettingsData.xml", SettingsFile.Path);

            isFileDownloaded = await ftp.GetFileAsync("profile.jpg", ProfilePictureFile.Path);

            isConnected = isFileDownloaded;

            (App.Current as App).SettingsXML = XDocument.Load(await ApplicationData.Current.LocalFolder.OpenStreamForReadAsync("SettingsData.xml"));
            (App.Current as App).NamesXML    = XDocument.Load(await ApplicationData.Current.LocalFolder.OpenStreamForReadAsync("SettingsData.xml"));

            await ftp.DisconnectAsync();
        }
示例#2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            m_bgWorker.WorkerReportsProgress      = true;
            m_bgWorker.WorkerSupportsCancellation = true;

            m_bgWorker.DoWork             += new DoWorkEventHandler(m_bgWorker_DoWork);
            m_bgWorker.ProgressChanged    += new ProgressChangedEventHandler(m_bgWorker_ProgressChanged);
            m_bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(m_bgWorker_RunWorkerCompleted);

            // Unlocking is only required once.
            bool success = m_ftp.UnlockComponent("Anything for 30-day trial");

            if (!success)
            {
                txtLastError.Text = m_ftp.LastErrorText;
            }

            // Make sure events are enabled.  Get heartbeat events every 100 millisec.
            m_ftp.EnableEvents   = true;
            m_ftp.HeartbeatMs    = 100;
            m_ftp.KeepSessionLog = true;

            btnUpload.Enabled     = false;
            btnDownload.Enabled   = false;
            btnDisconnect.Enabled = false;

            // Add event callbacks for m_ftp
            m_ftp.OnAbortCheck  += new Chilkat.Ftp2.AbortCheckEventHandler(m_ftp_OnAbortCheck);
            m_ftp.OnPercentDone += new Chilkat.Ftp2.PercentDoneEventHandler(m_ftp_OnFtpPercentDone);
        }
示例#3
0
        /// <summary>
        /// FtpInternalDownload() --> Performs an FTP Download.
        /// </summary>
        /// <param name="folder">Indicates the folder where the file will be uploaded</param>
        /// <param name="localfolders">Indicates the local folders where the file will be downloaded to</param>
        /// <param name="apps">Indicates the eFlow apps for which the download are going to be placed</param>
        /// <param name="hostname">Indicates the host name where the file will be uploaded</param>
        /// <param name="username">Indicates the name of the user allowed to login into the hostname</param>
        /// <param name="pwd">Indicates the password of the user allowed to login into the hostname</param>
        /// <example><code>s.FtpInternalDownload("/images_receive", localfolders, apps, "ftp.doksend.com", "supplierportaluser", "e7low5!!");</code></example>
        protected bool FtpInternalDownload(string folder, string[] localfolders, string[] apps, string hostname, string username, string pwd)
        {
            bool result = false;

            try
            {
                using (Chilkat.Ftp2 ftp = new Chilkat.Ftp2())
                {
                    if (ftp.UnlockComponent(Constants.cStrChilkatFtpLic))
                    {
                        ftp.Hostname = hostname;
                        ftp.Username = username;
                        ftp.Password = pwd;

                        ftp.Passive = true;

                        if (ftp.Connect())
                        {
                            if (ftp.ChangeRemoteDir(folder))
                            {
                                ftp.ListPattern = Constants.cStrAllAll;

                                for (int i = 0; i <= ftp.NumFilesAndDirs - 1; i++)
                                {
                                    if (localfolders.Length > 0 && apps.Length > 0)
                                    {
                                        string fl  = ftp.GetFilename(i);
                                        string lfn = GetLocalFolderFileName(fl, localfolders, apps);

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

                                        result = ftp.GetFile(fl, lfn);
                                        Thread.Sleep(50);

                                        ftp.DeleteRemoteFile(fl);
                                        Thread.Sleep(50);
                                    }
                                }
                            }
                        }
                        else
                        {
                            Logging.WriteLog(ftp.LastErrorText);
                        }

                        ftp.Disconnect();
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.WriteLog(ex.ToString());
            }

            return(result);
        }
示例#4
0
        private void ConnectingToFtp()
        {
            ftp.UnlockComponent("test");

            ftp.Hostname = "ftp.bodirectors.com";
            ftp.Username = (App.Current as App).Email + "@bodirectors.com";
            ftp.Password = (App.Current as App).Password;
        }
示例#5
0
        /// <summary>
        /// FtpInternalCleanupImageWithNoCollections() --> Cleanup images which do not have a corresponding collection on the portal (FTP).
        /// </summary>
        /// <param name="cust">Indicates the name of supplier portal customer.</param>
        /// <param name="app">Indicates the name of eFlow application.</param>
        /// <param name="fn">Indicates the name of the file to upload.</param>
        /// <param name="fnUp">Indicates the name of the file on the server (how it will be called once uploaded).</param>
        /// <param name="folder">Indicates the folder where the file will be uploaded</param>
        /// <param name="hostname">Indicates the host name where the file will be uploaded</param>
        /// <param name="username">Indicates the name of the user allowed to login into the hostname</param>
        /// <param name="pwd">Indicates the password of the user allowed to login into the hostname</param>
        /// <example><code>s.FtpInternalCleanupImageWithNoCollections("topimagesystems.com", "CLS", "00000323.tif", "/images", "ftp.doksend.com", "supplierportaluser", "e7low5!!");</code></example>
        protected bool FtpInternalCleanupImageWithNoCollections(string cust, string app, string fn, string fnUp, string folder, string hostname, string username, string pwd)
        {
            bool result = false;

            try
            {
                using (Chilkat.Ftp2 ftp = new Chilkat.Ftp2())
                {
                    if (ftp.UnlockComponent(Constants.cStrChilkatFtpLic))
                    {
                        ftp.Hostname = hostname;
                        ftp.Username = username;
                        ftp.Password = pwd;

                        ftp.Passive = true;

                        if (ftp.Connect())
                        {
                            if (ftp.ChangeRemoteDir(folder))
                            {
                                // Cleanup images which do not have a corresponding collection on the portal
                                ftp.ListPattern = Constants.cStrAllTif;
                                for (int i = 0; i <= ftp.NumFilesAndDirs - 1; i++)
                                {
                                    string fl        = ftp.GetFilename(i);
                                    string customer  = fl.Substring(0, fl.IndexOf("_"));
                                    string appName   = ExtractStrInBetween(fl, "_", "-");
                                    string batchName = ExtractStrInBetween(fl, "-", Constants.cStrTif);

                                    //if (HttpPostCollectionDataQry(customer + "_" + appName,
                                    if (HttpPostCollectionDataQry(cust + "_" + appName,
                                                                  Constants.cStrHttpPostCollectionDatacollectionNameQryCln,
                                                                  batchName, 80, false).ToLower().Contains(Constants.cStrEmptyJsonResponse))
                                    {
                                        Thread.Sleep(50);
                                        ftp.DeleteRemoteFile(fl);
                                    }
                                }
                            }
                        }
                        else
                        {
                            Logging.WriteLog(ftp.LastErrorText);
                        }

                        ftp.Disconnect();
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.WriteLog(ex.ToString());
            }

            return(result);
        }
示例#6
0
        public static void DownloadDirectory(string FTPAddress, string Dir, string UN, string PW)
        {
            Chilkat.Ftp2 ftp = new Chilkat.Ftp2();

            bool success;

            //  Any string unlocks the component for the 1st 30-days.
            success = ftp.UnlockComponent("RCKVGHFTP_hK0TOpsv6An5");
            if (success != true)
            {
                Console.WriteLine(ftp.LastErrorText);
                return;
            }

            ftp.Hostname       = FTPAddress;
            ftp.Username       = UN;
            ftp.Password       = PW;
            ftp.Passive        = false;
            ftp.KeepSessionLog = true;

            //  Connect and login to the FTP server.
            success = ftp.Connect();
            if (success != true)
            {
                Console.WriteLine(ftp.LastErrorText);
                return;
            }

            //  Set the current remote directory to the root of
            //  the tree to be downloaded.
            success = ftp.ChangeRemoteDir("/" + Dir);
            if (success != true)
            {
                Console.WriteLine(ftp.LastErrorText);
                return;
            }

            //  Recursively download all non-existant and newer files.
            int    mode     = 2;
            string localDir = Path.GetDirectoryName(Application.ExecutablePath);

            success = ftp.SyncLocalTree(localDir + "/" + GV.UpdateAvailable, mode);
            if (success != true)
            {
                Console.WriteLine(ftp.LastErrorText);
                return;
            }

            ftp.Disconnect();

            //  Display the session log.
            Console.WriteLine(ftp.SessionLog);
        }
示例#7
0
        public static void DownloadFile(string FTPAddress, string Dir, string UN, string PW, string Filename)
        {
            Chilkat.Ftp2 ftp = new Chilkat.Ftp2();

            bool success;

            //  Any string unlocks the component for the 1st 30-days.
            success = ftp.UnlockComponent("RCKVGHFTP_hK0TOpsv6An5");
            if (success != true)
            {
                Console.WriteLine(ftp.LastErrorText);
                return;
            }

            ftp.Hostname = FTPAddress;
            ftp.Username = UN;
            ftp.Password = PW;
            ftp.Passive  = false;
            //  The default data transfer mode is "Active" as opposed to "Passive".

            //  Connect and login to the FTP server.
            success = ftp.Connect();
            if (success != true)
            {
                Console.WriteLine(ftp.LastErrorText);
                return;
            }

            //  Change to the remote directory where the file is located.
            //  This step is only necessary if the file is not in the root directory
            //  for the FTP account.
            success = ftp.ChangeRemoteDir(Dir);
            if (success != true)
            {
                Console.WriteLine(ftp.LastErrorText);
                return;
            }

            //  Download a file.
            string localFilename  = Filename;
            string remoteFilename = Filename;

            success = ftp.GetFile(remoteFilename, localFilename);
            if (success != true)
            {
                Console.WriteLine(ftp.LastErrorText);
                return;
            }

            ftp.Disconnect();

            Console.WriteLine("File Downloaded!");
        }
示例#8
0
        private async Task DownloadFile()
        {
            await Task.Delay(200);

            InfoText = DownloadConnectionStatus.Text;
            ftp.UnlockComponent("test");

            ftp.Hostname = "ftp.bodirectors.com";
            ftp.Username = (App.Current as App).Email + "@bodirectors.com";
            ftp.Password = (App.Current as App).Password;

            StorageFile file = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync("SettingsData.xml");

            DownloadConnectionStatus.Text = "Getting latest file from server.";
            await ftp.ConnectAsync();

            isFileAvailable = await ftp.GetFileAsync("SettingsData.xml", file.Path);

            await ftp.DisconnectAsync();

            DownloadConnectionStatus.Text = "File Downlaoded\n\n";
            isFileAvailable = false;
        }
示例#9
0
        /// <summary>
        /// FtpInternalSendFile() --> Performs an FTP Upload.
        /// </summary>
        /// <param name="cust">Indicates the name of supplier portal customer.</param>
        /// <param name="app">Indicates the name of eFlow application.</param>
        /// <param name="fn">Indicates the name of the file to upload.</param>
        /// <param name="fnUp">Indicates the name of the file on the server (how it will be called once uploaded).</param>
        /// <param name="folder">Indicates the folder where the file will be uploaded</param>
        /// <param name="hostname">Indicates the host name where the file will be uploaded</param>
        /// <param name="username">Indicates the name of the user allowed to login into the hostname</param>
        /// <param name="pwd">Indicates the password of the user allowed to login into the hostname</param>
        /// <example><code>s.FtpInternalSendFile("topimagesystems.com", "CLS", "00000323.tif", "/images", "ftp.doksend.com", "supplierportaluser", "e7low5!!");</code></example>
        protected bool FtpInternalSendFile(string cust, string app, string fn, string fnUp, string folder, string hostname, string username, string pwd)
        {
            bool result = false;

            try
            {
                using (Chilkat.Ftp2 ftp = new Chilkat.Ftp2())
                {
                    if (ftp.UnlockComponent(Constants.cStrChilkatFtpLic))
                    {
                        ftp.Hostname = hostname;
                        ftp.Username = username;
                        ftp.Password = pwd;

                        ftp.Passive = true;

                        if (ftp.Connect())
                        {
                            if (ftp.ChangeRemoteDir(folder))
                            {
                                if (ftp.GetSizeByName(fnUp) < 0)
                                {
                                    if (File.Exists(fn))
                                    {
                                        result = ftp.PutFile(fn, fnUp);
                                        Thread.Sleep(50);
                                    }
                                }
                            }
                        }
                        else
                        {
                            Logging.WriteLog(ftp.LastErrorText);
                        }

                        ftp.Disconnect();
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.WriteLog(ex.ToString());
            }

            return(result);
        }
示例#10
0
        private async void UploadFile()
        {
            ftp.UnlockComponent("test");

            ftp.Hostname = "ftp.bodirectors.com";
            ftp.Username = (App.Current as App).Email + "@bodirectors.com";
            ftp.Password = (App.Current as App).Password;



            await ftp.ConnectAsync();

            isFileAvailable = await ftp.PutFileAsync(file.Path, "OutputNames.xml");

            await ftp.DisconnectAsync();

            isFileAvailable = false;
        }
示例#11
0
        public void bgworkerStartUpload_DoWorkHandler(object sender, DoWorkEventArgs e)
        {
            ApiHelper api = new ApiHelper();
            BackgroundWorker bgworkerStartUpload = sender as BackgroundWorker;
            Dictionary<string, string> fileInfo = (Dictionary<string, string>)e.Argument;
            Dictionary<string, string> asyncResult = new Dictionary<string, string>();
            asyncResult.Add("IsCompleted", "false");
            asyncResult.Add("FileId", fileInfo["FileId"]);
            asyncResult.Add("RemoteFilePath", fileInfo["RemoteFilePath"]);

            // Asynchronous FTP Upload
            Chilkat.Ftp2 ftp = new Chilkat.Ftp2();

            bool success;

            success = ftp.UnlockComponent(GlobalHelper.ComponentCode);
            if (success != true)
            {
                MessageBox.Show(ftp.LastErrorText);
                return;
            }

            ftp.Hostname = GlobalHelper.FtpHost;
            ftp.Username = GlobalHelper.FtpUsername;
            ftp.Password = GlobalHelper.FtpPasswrod;
            // Resume upload
            ftp.RestartNext = true;

            // Connect and login to the FTP server.
            success = ftp.Connect();
            if (success != true)
            {
                MessageBox.Show(ftp.LastErrorText);
                return;
            }

            string localFilename = fileInfo["LocalFilePath"];
            string remoteFilename = fileInfo["RemoteFilePath"];
            long localFilesize = Convert.ToInt64(fileInfo["LocalFileSize"]);

            success = ftp.AsyncPutFileStart(localFilename, remoteFilename);
            if (success != true)
            {
                MessageBox.Show(ftp.LastErrorText);
                return;
            }

            while (ftp.AsyncFinished != true)
            {
                if (_cancelList.Contains(fileInfo["FileId"]))
                {
                    ftp.AsyncAbort();
                    break;
                }

                if (api.CheckPath(remoteFilename))
                {
                    long remoteFilesize = api.GetFileSize(remoteFilename);
                    double percentage = ((double)remoteFilesize / (double)localFilesize) * 100;
                    bgworkerStartUpload.ReportProgress((int)percentage);
                }

                // Sleep 0.5 second.
                ftp.SleepMs(500);
            }

            bool uploadSuccess = false;
            // Did the upload succeed?
            if (ftp.AsyncSuccess == true)
            {
                uploadSuccess = true;
                bgworkerStartUpload.ReportProgress(100);
                asyncResult["IsCompleted"] = "true";
            }
            else
            {

            }

            ftp.Disconnect();
            ftp.Dispose();

            // Change Local file name back to original
            string originalFilePath = fileInfo["LocalFilePath"].Replace(GlobalHelper.TempUploadFileExt, String.Empty);
            if (uploadSuccess || _cancelList.Contains(fileInfo["FileId"]))
            {
                File.Move(fileInfo["LocalFilePath"], originalFilePath);
            }

            if (uploadSuccess)
            {
                // Move local file to Recycle bin
                FileSystem.DeleteFile(originalFilePath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
                // Remove temp extension from remote file
                string newName = remoteFilename.Replace(GlobalHelper.TempUploadFileExt, String.Empty);
                api.Rename(remoteFilename, newName);
                // Insert record into db
                int categoryId = Convert.ToInt32(fileInfo["ModelFileCategoryId"]);
                int lineId = Convert.ToInt32(fileInfo["ModelLineId"]);
                CFile.InsertOrUpdate(null, categoryId, lineId, fileInfo["ModelOriginFileName"],
                                           fileInfo["ModelFileName"], false, GlobalHelper.LoginUserID, fileInfo["ModelFileHash"]);
            }

            e.Result = asyncResult;
        }
示例#12
0
        public void bgworkerStartDownload_DoWorkHandler(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker bgworkerStartDownload = sender as BackgroundWorker;
            Dictionary<string, string> fileInfo = (Dictionary<string, string>)e.Argument;
            Dictionary<string, string> asyncResult = new Dictionary<string, string>();
            asyncResult.Add("IsCompleted", "false");
            asyncResult.Add("FileId", fileInfo["FileId"]);
            asyncResult.Add("LocalFilePath", "");

            // Asynchronous FTP Download
            Chilkat.Ftp2 ftp = new Chilkat.Ftp2();

            bool success;

            success = ftp.UnlockComponent(GlobalHelper.ComponentCode);
            if (success != true)
            {
                MessageBox.Show(ftp.LastErrorText);
                return;
            }

            ftp.Hostname = GlobalHelper.FtpHost;
            ftp.Username = GlobalHelper.FtpUsername;
            ftp.Password = GlobalHelper.FtpPasswrod;
            // Resume download
            ftp.RestartNext = true;

            // Connect and login to the FTP server.
            success = ftp.Connect();
            if (success != true)
            {
                MessageBox.Show(ftp.LastErrorText);
                return;
            }

            string localFilename = String.Format(@"{0}\{1}",fileInfo["LocalFilePath"], fileInfo["LocalFileName"]);
            asyncResult["LocalFilePath"] = localFilename;
            string remoteFilename = fileInfo["RemoteFilePath"];
            long remoteFilesize = Convert.ToInt64(fileInfo["RemoteFileSize"]);

            success = ftp.AsyncGetFileStart(remoteFilename, localFilename);
            if (success != true)
            {
                MessageBox.Show(ftp.LastErrorText);
                return;
            }

            while (ftp.AsyncFinished != true)
            {
                if (_cancelList.Contains(fileInfo["FileId"]))
                {
                    ftp.AsyncAbort();
                    break;
                }

                if (File.Exists(localFilename))
                {
                    FileInfo localFile = new FileInfo(localFilename);
                    double percentage = ((double)localFile.Length / (double)remoteFilesize) * 100;
                    bgworkerStartDownload.ReportProgress((int)percentage);
                }

                // Sleep 0.5 second.
                ftp.SleepMs(500);
            }

            bool downloadSuccess = false;
            // Did the download succeed?
            if (ftp.AsyncSuccess == true)
            {
                downloadSuccess = true;
                bgworkerStartDownload.ReportProgress(100);
                asyncResult["IsCompleted"] = "true";
            }
            else
            {

            }

            ftp.Disconnect();
            ftp.Dispose();

            if (downloadSuccess)
            {
                File.Move(localFilename, localFilename.Replace(GlobalHelper.TempDownloadFileExt, String.Empty));
            }

            e.Result = asyncResult;
        }
示例#13
0
 private Chilkat.Ftp2 SetInfomation(string host, int port, string username, string password)
 {
     Chilkat.Ftp2 ftp = new Chilkat.Ftp2();
     ftp.UnlockComponent(key);
     ftp.Hostname = host;
     ftp.Port = port;
     ftp.Username = username;
     ftp.Password = password;
     ftp.SetTypeAscii();
     return ftp;
 }