Exemplo n.º 1
0
        private void btnDisconnect_Click(object sender, EventArgs e)
        {
            // Reset progress bars, the abort flag, and give the abort button focus.
            progressBar2.Value = 0;
            progressBar1.Value = 0;
            m_abort            = false;
            btnAbort.Focus();

            bool success = m_ftp.Disconnect();

            if (!success)
            {
                txtLastError.Text  = m_ftp.LastErrorText;
                txtSessionLog.Text = m_ftp.SessionLog;
                MessageBox.Show("Failed to disconnect");
                return;
            }

            // Show this even on success...
            txtLastError.Text  = m_ftp.LastErrorText;
            txtSessionLog.Text = m_ftp.SessionLog;

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

            MessageBox.Show("Disconnected!");
        }
Exemplo n.º 2
0
        private void ButtonBorrarImagen_Click(object sender, EventArgs e)
        {
            Chilkat.Ftp2 ftp = new Chilkat.Ftp2();
            bool         success;

            ftp.Hostname = "www.repuestosdemoviles.es";
            ftp.Username = "******";
            ftp.Password = "******";
            success      = ftp.Connect();
            if (success != true)
            {
                Console.WriteLine(ftp.LastErrorText);
                return;
            }
            string codigo  = (string)gridViewArticulos.GetRowCellValue(gridViewArticulos.FocusedRowHandle, colCodigo);
            string cwd     = "httpdocs/ebay/imagenes/" + codigo.Trim();
            string BaseUrl = "http://www.repuestosdemoviles.es/ebay/imagenes/" + codigo.Trim();

            success = ftp.ChangeRemoteDir(cwd);
            var    i        = imageSlider1.CurrentImageIndex;
            string filename = ListaImagenes[i];

            ftp.DeleteRemoteFile(filename);
            ftp.Disconnect();
            CargarImagenes(codigo);
        }
Exemplo n.º 3
0
        private void SubirImagen(string file, string codigo)
        {
            Chilkat.Ftp2 ftp = new Chilkat.Ftp2();
            bool         success;

            ftp.Hostname = "www.repuestosdemoviles.es";
            ftp.Username = "******";
            ftp.Password = "******";
            success      = ftp.Connect();
            if (success != true)
            {
                Console.WriteLine(ftp.LastErrorText);
                return;
            }

            string cwd     = "httpdocs/ebay/imagenes/" + codigo.Trim();
            string BaseUrl = "http://www.repuestosdemoviles.es/ebay/imagenes/" + codigo.Trim();

            success = ftp.ChangeRemoteDir(cwd);
            success = ftp.PutFile(file, Path.GetFileName(file));
            if (success != true)
            {
                Console.WriteLine(ftp.LastErrorText);
                return;
            }
            ftp.Disconnect();
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        // rename file from directory. Takes first argument from command line and
        // checks if valid input, renames file from directory and outputs success message
        static void Main(string[] args)
        {
            String[] arguments = Environment.GetCommandLineArgs();
            String   oldFile   = arguments[1];
            String   newFile   = arguments[2];

            System.IO.FileInfo file = new System.IO.FileInfo(path);
            try
            {
                if (File.Exists(path))
                {
                    Chilkat.Ftp2 ftp = new Chilkat.Ftp2();

                    ftp.Hostname = "ftp.example.com";
                    ftp.Username = "******";
                    ftp.Password = "******";

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

                    // Set the current remote directory to where the file
                    // is located:
                    success = ftp.ChangeRemoteDir(path);
                    if (success != true)
                    {
                        Debug.WriteLine(ftp.LastErrorText);
                        return;
                    }

                    // Rename the remote file (or directory)

                    success = ftp.RenameRemoteFile(oldFile, newFile);
                    if (success != true)
                    {
                        Debug.WriteLine(ftp.LastErrorText);
                        return;
                    }

                    success = ftp.Disconnect();
                    Console.WriteLine("\nProcess complete: \"" + oldFile + "\" deleted \"" + newFile);
                }
                else
                {
                    Console.WriteLine("file not found");
                }
            }
            catch (System.IO.IOException e)
            {
                Console.WriteLine("{0} is not a valid file or directory.", e);
            }
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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!");
        }
Exemplo n.º 9
0
        private void CargarImagenes(string codigo)
        {
            imageSlider1.Images.Clear();
            ListaImagenes.Clear();
            Chilkat.Ftp2 ftp = new Chilkat.Ftp2();
            bool         success;

            //success= ftp.UnlockComponent("CRNsu3.CB10699_Zu6BhW7yjEkG");
            //if (success != true)
            //{
            //    Console.WriteLine(ftp.LastErrorText);
            //    return;
            //}

            ftp.Hostname = "www.repuestosdemoviles.es";
            ftp.Username = "******";
            ftp.Password = "******";
            success      = ftp.Connect();
            if (success != true)
            {
                Console.WriteLine(ftp.LastErrorText);
                return;
            }

            string cwd     = "httpdocs/ebay/imagenes/" + codigo.Trim();
            string BaseUrl = "http://www.repuestosdemoviles.es/ebay/imagenes/" + codigo.Trim();

            success = ftp.ChangeRemoteDir(cwd);
            int i;
            int n;
            int NumeroFotos = 0;

            n = ftp.GetDirCount();
            if (n > 0)
            {
                for (i = 0; i <= n - 1; i++)
                {
                    if (ftp.GetIsDirectory(i) == false)
                    {
                        WebClient    wc       = new WebClient();
                        string       filename = BaseUrl + "/" + ftp.GetFilename(i);
                        byte[]       bytes    = wc.DownloadData(filename);
                        MemoryStream ms       = new MemoryStream(bytes);
                        imageSlider1.Images.Add(Image.FromStream(ms));
                        ListaImagenes.Add(ftp.GetFilename(i));
                        NumeroFotos++;
                    }
                }
            }
            success = ftp.Disconnect();
            textEditNumeroImagenes.Text = NumeroFotos.ToString();
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            GenerarArchivo();
            Console.WriteLine("archivo generado con exito");
            Console.ReadKey();

            Chilkat.Global glob          = new Chilkat.Global();
            bool           successUnlock = glob.UnlockBundle("Anything for 30-day trial");

            if (successUnlock != true)
            {
                Console.WriteLine(glob.LastErrorText);
                return;
            }

            int status = glob.UnlockStatus;

            if (status == 2)
            {
                Console.WriteLine("Unlocked using purchased unlock code.");
            }
            else
            {
                Chilkat.Ftp2 ftp = new Chilkat.Ftp2();

                ftp.Hostname = "localhost";
                ftp.Username = "******";
                ftp.Password = "******";

                // Connect and login to the FTP server.
                bool success = ftp.Connect();
                if (success != true)
                {
                    Console.WriteLine(ftp.LastErrorText);
                    Console.WriteLine("Press any key to exit...");
                    Console.ReadKey();
                    return;
                }

                // Change to the remote directory where the file will be uploaded.
                success = ftp.ChangeRemoteDir("doc");
                if (success != true)
                {
                    Console.WriteLine(ftp.LastErrorText);
                    return;
                }

                // Upload a file.
                string localPath      = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName) + @"\prueba.txt";
                string remoteFilename = "prueba.txt";

                success = ftp.PutFile(localPath, remoteFilename);
                if (success != true)
                {
                    Console.WriteLine(ftp.LastErrorText);
                    Console.WriteLine("Press any key to exit...");
                    Console.ReadKey();
                    return;
                }

                success = ftp.Disconnect();

                Console.WriteLine("File Uploaded!");
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();
            }
        }
Exemplo n.º 12
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;
        }
Exemplo n.º 13
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;
        }