예제 #1
0
        public FTPDirectory(bool isFolderPicker, FTPCredentialsConfig ftpcreds)
        {
            InitializeComponent();
            this.isFolderPicker = isFolderPicker;

            ImageList smallimagelist = new ImageList();

            smallimagelist.Images.Add(Bitmap.FromFile("resources\\icons\\folderimage.bmp"));
            smallimagelist.Images.Add(Bitmap.FromFile("resources\\icons\\fileimage.bmp"));
            listView1.SmallImageList = smallimagelist;
            ftpUtils = new FTPUtils(ftpcreds);
            ftpUtils.startSession();

            if (!String.IsNullOrEmpty(path))
            {
                remoteFileInfoList = ftpUtils.getDirectoryListing(path, isFolderPicker, false);
                previousPath       = path;
            }
            else
            {
                remoteFileInfoList = ftpUtils.getDirectoryListing("/", isFolderPicker, false);
            }
            loadDataToListview();
            tbpath.Text = previousPath;
        }
예제 #2
0
        private void bTestConnection_Click(object sender, EventArgs e)
        {
            if (!performChecks(false))
            {
                return;
            }
            FTPCredentialsConfig config = new FTPCredentialsConfig();

            config.host                  = tbHost.Text;
            config.port                  = Convert.ToInt32(tbPort.Text);
            config.usePrivateKey         = cbPrivateKey.Checked;
            config.privateKeyPath        = tbPrivateKey.Text;
            config.SshHostKeyFingerprint = sshKeyFingerprint;
            config.username              = tbUsername.Text;
            config.password              = tbPassword.Text;
            switch (cmbProtocol.SelectedIndex)
            {
            case 0:
                config.useSFTP = false;
                break;

            case 1:
                config.useSFTP = true;
                break;

            default:
                config.useSFTP = false;
                break;
            }
            adapter.setFtpLocation(config);
            adapter.testConnection();
        }
예제 #3
0
        private List <string> getFtpDirectoryListing(firedumpdbDataSet.backup_locationsRow location, string path)
        {
            List <string>        filesindir = new List <string>();
            FTPCredentialsConfig ftpConfig  = new FTPCredentialsConfig();

            ftpConfig.id       = location.id;
            ftpConfig.host     = location.host;
            ftpConfig.port     = (int)location.port;
            ftpConfig.username = location.username;
            ftpConfig.password = location.password;
            if (location.usesftp == 1)
            {
                ftpConfig.useSFTP = true;
                ftpConfig.SshHostKeyFingerprint = location.ssh_key_fingerprint;
            }
            if (!string.IsNullOrEmpty(location.ssh_key))
            {
                ftpConfig.usePrivateKey  = true;
                ftpConfig.privateKeyPath = location.ssh_key;
            }
            FTPUtils ftputils = new FTPUtils(ftpConfig);

            ftputils.startSession();
            List <WinSCP.RemoteFileInfo> dirList = ftputils.getDirectoryListing(path, false, false);

            ftputils.disposeSession();
            foreach (WinSCP.RemoteFileInfo info in dirList)
            {
                filesindir.Add(info.FullName);
            }
            return(filesindir);
        }
예제 #4
0
        private void bPathOnServer_Click(object sender, EventArgs e)
        {
            FTPCredentialsConfig config = new FTPCredentialsConfig();

            config.host                  = tbHost.Text;
            config.port                  = Convert.ToInt32(tbPort.Text);
            config.usePrivateKey         = cbPrivateKey.Checked;
            config.privateKeyPath        = tbPrivateKey.Text;
            config.SshHostKeyFingerprint = sshKeyFingerprint;
            config.username              = tbUsername.Text;
            config.password              = tbPassword.Text;
            switch (cmbProtocol.SelectedIndex)
            {
            case 0:
                config.useSFTP = false;
                break;

            case 1:
                config.useSFTP = true;
                break;

            default:
                config.useSFTP = false;
                break;
            }
            //check creds

            FTPDirectory ftpdirectory = new FTPDirectory(true, config);

            if (!String.IsNullOrEmpty(tbChooseAPath.Text))
            {
                ftpdirectory.path = tbChooseAPath.Text;
            }

            DialogResult res = ftpdirectory.ShowDialog();

            if (res == DialogResult.OK)
            {
                bool isDirectory = ftpdirectory.isDirectory;
                //an den einai pare to telefteo filename
                if (!isDirectory)
                {
                    tbFilename.Text    = ftpdirectory.path.Substring(ftpdirectory.path.LastIndexOf('/') + 1);
                    tbChooseAPath.Text = ftpdirectory.path.Substring(0, ftpdirectory.path.LastIndexOf('/'));
                    if (!tbChooseAPath.Text.EndsWith("/"))
                    {
                        tbChooseAPath.Text = tbChooseAPath.Text + "/";
                    }
                }
                else
                {
                    tbChooseAPath.Text = ftpdirectory.path;
                    if (!tbChooseAPath.Text.EndsWith("/"))
                    {
                        tbChooseAPath.Text = tbChooseAPath.Text + "/";
                    }
                }
            }
        }
예제 #5
0
        public void demoFTP()
        {
            FTPCredentialsConfig config = new FTPCredentialsConfig();

            config.host                  = "cspeitch.com";
            config.port                  = 22;
            config.username              = "";
            config.password              = "";
            config.sourcePath            = "D:\\MyStuff\\DSC_0133.JPG";
            config.locationPath          = "/home/cspeitch/eikona";
            config.SshHostKeyFingerprint = "";
            config.useSFTP               = true;

            FTPUtils ftp = new FTPUtils(config);

            /*
             * FTPConnectionResultSet res = ftp.testConnection();
             * Console.WriteLine("Was Succesful: "+res.wasSuccessful);
             * Console.WriteLine("Error Message: " + res.errorMessage);
             * Console.WriteLine("SSH fingerprint: "+res.sshHostKeyFingerprint);*/

            //ftp.sendFile();
            ftp.startSession();
            List <RemoteFileInfo> files = ftp.getDirectoryListing("/", false, false);

            foreach (RemoteFileInfo file in files)
            {
                Console.WriteLine(file.IsDirectory + " " + file.Name);
            }
            Console.WriteLine();
            files = ftp.getDirectoryListing("/home/cspeitch", false, false);
            foreach (RemoteFileInfo file in files)
            {
                Console.WriteLine(file.IsDirectory + " " + file.Name);
            }
            Console.WriteLine();
            files = ftp.getDirectoryListing("/home/cspeitch/animeapp", false, false);
            foreach (RemoteFileInfo file in files)
            {
                Console.WriteLine(file.IsDirectory + " " + file.Name);
            }
            Console.WriteLine();
            ftp.disposeSession();
        }
예제 #6
0
        public void demoFTP()
        {
            FTPCredentialsConfig config = new FTPCredentialsConfig();

            config.host                  = "cspeitch.com";
            config.port                  = 22;
            config.username              = "";
            config.password              = "";
            config.sourcePath            = "D:\\MyStuff\\DSC_0133.JPG";
            config.locationPath          = "/home/cspeitch/eikona";
            config.SshHostKeyFingerprint = "";
            config.useSFTP               = true;

            FTPUtils ftp = new FTPUtils(config);

            ftp.startSession();
            List <RemoteFileInfo> files = ftp.getDirectoryListing("/", false, false);

            foreach (RemoteFileInfo file in files)
            {
                Console.WriteLine(file.IsDirectory + " " + file.Name);
            }
            Console.WriteLine();
            files = ftp.getDirectoryListing("/home/cspeitch", false, false);
            foreach (RemoteFileInfo file in files)
            {
                Console.WriteLine(file.IsDirectory + " " + file.Name);
            }
            Console.WriteLine();
            files = ftp.getDirectoryListing("/home/cspeitch/animeapp", false, false);
            foreach (RemoteFileInfo file in files)
            {
                Console.WriteLine(file.IsDirectory + " " + file.Name);
            }
            Console.WriteLine();
            ftp.disposeSession();
        }
예제 #7
0
        public void startSave() //thelei douleia afti
        {
            if (locations.Count == 0)
            {
                onSaveError("Save started with no locations");
                return;
            }
            LocationCredentialsConfig config;
            DataTable data = backup_adapter.GetDataByID(locations[0]);

            if (data.Rows.Count == 0)
            {
                onSaveError("Location not found in the database");
                return;
            }
            long type = (Int64)data.Rows[0]["service_type"];

            adapter               = new LocationAdapter();
            adapter.Progress     += onSaveProgressHandler;
            adapter.SaveComplete += onSaveCompleteHandler;
            adapter.SaveError    += onSaveErrorHandler;
            adapter.setLocationId(locations[0]);
            switch (type) //edw gemizei to config apo to database prepei na kanei diaforetiko query gia kathe diaforetiko type kai na gemisei to config prin to settarei ston adapter
            {
            case 0:       //file system
                config              = new LocationCredentialsConfig();
                config.fnamePrefix  = fnamePrefix;
                config.sourcePath   = sourcePath;
                config.locationPath = (string)data.Rows[0]["path"];
                adapter.setLocalLocation(config);
                break;

            case 1:     //FTP
                config              = new FTPCredentialsConfig();
                config.fnamePrefix  = fnamePrefix;
                config.sourcePath   = sourcePath;
                config.locationPath = (string)data.Rows[0]["path"] + (string)data.Rows[0]["filename"];
                ((FTPCredentialsConfig)config).id   = (Int64)data.Rows[0]["id"];
                ((FTPCredentialsConfig)config).host = (string)data.Rows[0]["host"];
                config.port     = unchecked ((int)(Int64)data.Rows[0]["port"]);
                config.username = (string)data.Rows[0]["username"];
                config.password = (string)data.Rows[0]["password"];
                Int64 useSFTP = (Int64)data.Rows[0]["usesftp"];
                if (useSFTP == 1)
                {
                    ((FTPCredentialsConfig)config).useSFTP = true;
                    ((FTPCredentialsConfig)config).SshHostKeyFingerprint = (string)data.Rows[0]["ssh_key_fingerprint"];
                }
                string keypath = (string)data.Rows[0]["ssh_key"];
                if (!string.IsNullOrEmpty(keypath))
                {
                    ((FTPCredentialsConfig)config).usePrivateKey  = true;
                    ((FTPCredentialsConfig)config).privateKeyPath = keypath;
                }
                adapter.setFtpLocation(config);
                break;

            case 2:     //Dropbox
                DropBoxCredentials boxcreds = new DropBoxCredentials();
                boxcreds.Path          = (string)data.Rows[0]["path"];
                boxcreds.Name          = (string)data.Rows[0]["name"];
                boxcreds.FileName      = (string)data.Rows[0]["filename"];
                boxcreds.Token         = (string)data.Rows[0]["access_token"];
                boxcreds.LocalFilePath = sourcePath;
                //EDW SETUP TO CONFIG
                adapter.setCloudBoxLocation(boxcreds);
                break;

            case 3:     //Google drive
                config             = new LocationCredentialsConfig();
                config.fnamePrefix = fnamePrefix;
                //EDW SETUP TO CONFIG
                adapter.setCloudDriveLocation(config);
                break;

            default:
                onSaveError("Location type unknown");
                return;
            }

            onInnerSaveInit((string)data.Rows[0]["name"], unchecked ((int)type));
            Task managersendtask = new Task(adapter.sendFile);

            managersendtask.Start();
        }
예제 #8
0
 public FTPUtils(FTPCredentialsConfig config)
 {
     this.config = config;
     setupSessionOptions();
 }
예제 #9
0
        private void bChoosePathSv_Click(object sender, EventArgs e)
        {
            if (cmbSaveLocations.Items.Count == 0)
            {
                MessageBox.Show("No save locations available.", "File browser", MessageBoxButtons.OK, MessageBoxIcon.Error); return;
            }
            try
            {
                DataRow row  = firedumpdbDataSet.backup_locations.Rows[cmbSaveLocations.SelectedIndex];
                long    type = (Int64)row["service_type"];
                location = row;
                switch (type)
                {
                case 0:     //local
                    pathChooser(tbFilePathFs, tbFilePathSv);
                    break;

                case 1:     //ftp
                    FTPCredentialsConfig config = new FTPCredentialsConfig();
                    ((FTPCredentialsConfig)config).id   = (Int64)row["id"];
                    ((FTPCredentialsConfig)config).host = (string)row["host"];
                    config.port     = unchecked ((int)(Int64)row["port"]);
                    config.username = (string)row["username"];
                    config.password = EncryptionUtils.sDecrypt((string)row["password"]);
                    Int64 useSFTP = (Int64)row["usesftp"];
                    if (useSFTP == 1)
                    {
                        ((FTPCredentialsConfig)config).useSFTP = true;
                        ((FTPCredentialsConfig)config).SshHostKeyFingerprint = (string)row["ssh_key_fingerprint"];
                    }
                    string keypath = (string)row["ssh_key"];
                    if (!string.IsNullOrEmpty(keypath))
                    {
                        ((FTPCredentialsConfig)config).usePrivateKey  = true;
                        ((FTPCredentialsConfig)config).privateKeyPath = keypath;
                    }
                    FTPDirectory ftpdir = new FTPDirectory(false, config);
                    DialogResult res    = ftpdir.ShowDialog();
                    if (res == DialogResult.OK)
                    {
                        tbFilePathFs.Text = "";
                        tbFilePathSv.Text = ftpdir.path;
                        isLocal           = false;
                        checkCompressed(tbFilePathSv);
                    }

                    break;  //set to is local kai check compressed mi ksexastoun apo katw

                case 2:     //dropbox
                    break;

                case 3:     //google drive
                    break;

                default:
                    MessageBox.Show("Unknown save location type", "File browser", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error occured:\n" + ex.Message, "File browser", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #10
0
        public void startImport()
        {
            if (isLocal)
            {
                if (!File.Exists(path + filename))
                {
                    onImportError("File doesnt exist, path: " + path);
                    return;
                }
                templocalpath     = path;
                templocalfilename = filename;
                startDecompression();
            }
            else
            {
                //set config
                locationadapter               = new LocationAdapter();
                locationadapter.Progress     += downloadProgressHandler;
                locationadapter.SaveComplete += downloadCompleteHandler;
                locationadapter.SaveError    += downloadErrorHandler;
                LocationCredentialsConfig config;
                templocalpath = ConfigurationManager.getInstance().mysqlDumpConfigInstance.getSettings().tempSavePath;
                //calculate local path
                if (!File.Exists(path + filename))
                {
                    templocalfilename = filename;
                }
                else
                {
                    Random rnd       = new Random();
                    string extension = StringUtils.getExtension(filename);
                    templocalfilename = "Temp" + rnd.Next(1000000, 9999999) + extension;

                    Directory.CreateDirectory(templocalpath);


                    //checking if file exists
                    while (File.Exists(templocalpath + templocalfilename))
                    {
                        templocalfilename = "Temp" + rnd.Next(1000000, 9999999) + extension;
                    }
                }
                try
                {
                    long type = (Int64)locationdata["service_type"];
                    switch (type) //edw gemizei to config apo to database prepei na kanei diaforetiko query gia kathe diaforetiko type kai na gemisei to config prin to settarei ston adapter
                    {
                    case 0:       //file system
                        //De ginete na einai file system kai na erthei edw
                        break;

                    case 1:     //FTP
                        config              = new FTPCredentialsConfig();
                        config.sourcePath   = path + filename;
                        config.locationPath = templocalpath + templocalfilename;
                        ((FTPCredentialsConfig)config).id   = (Int64)locationdata["id"];
                        ((FTPCredentialsConfig)config).host = (string)locationdata["host"];
                        config.port     = unchecked ((int)(Int64)locationdata["port"]);
                        config.username = (string)locationdata["username"];
                        config.password = EncryptionUtils.sDecrypt((string)locationdata["password"]);
                        Int64 useSFTP = (Int64)locationdata["usesftp"];
                        if (useSFTP == 1)
                        {
                            ((FTPCredentialsConfig)config).useSFTP = true;
                            ((FTPCredentialsConfig)config).SshHostKeyFingerprint = (string)locationdata["ssh_key_fingerprint"];
                        }
                        string keypath = (string)locationdata["ssh_key"];
                        if (!string.IsNullOrEmpty(keypath))
                        {
                            ((FTPCredentialsConfig)config).usePrivateKey  = true;
                            ((FTPCredentialsConfig)config).privateKeyPath = keypath;
                        }
                        locationadapter.setFtpLocation(config);
                        break;

                    case 2:     //Dropbox
                        DropBoxCredentials boxcreds = new DropBoxCredentials();
                        //EDW SETUP TO CONFIG
                        locationadapter.setCloudBoxLocation(boxcreds);
                        break;

                    case 3:     //Google drive
                        config = new LocationCredentialsConfig();
                        //EDW SETUP TO CONFIG
                        locationadapter.setCloudDriveLocation(config);
                        break;

                    default:
                        onImportError("Location type unknown");
                        return;
                    }

                    onInnerProccessInit(Convert.ToInt32(type), 100);
                    locationadapter.getFile();
                }
                catch (InvalidCastException ex)
                {
                    onImportError("Save location data load failed:\n" + ex.Message);
                }
            }
        }