Exemplo n.º 1
0
        static void Main(string[] args)
        {
            try
            {
                WinSCP.Session session = new WinSCP.Session();

                session.Open(Program.sessionOptions.getSessionOptions());
                if (session.Opened)
                {
                    Console.WriteLine("Connected successfully");

                    Backup.BackupOptions backupOptions = new Backup.BackupOptions();

                    foreach (string remoteDirectory in backupOptions.getRemoteDirectories())
                    {
                        session.SynchronizeDirectories(WinSCP.SynchronizationMode.Local, backupOptions.getBackupDirectory(), remoteDirectory, false);
                        Console.WriteLine("backed up: " + remoteDirectory);
                    }
                    //session.GetFilesToDirectory(downloadBackupDirectory, @"C:\Users\adsy2\WS Backups\automated");
                }
                session.Close();
                Console.WriteLine("Disconnected");
            }
            catch (Exception exception)
            {
                Console.WriteLine("Failed connection: " + exception.Message);

                Console.Read();
            }
        }
Exemplo n.º 2
0
        // constructor
        public SadistaFunctions(string ipAddress, string username,
                                string password, string ssh_host_key_fingerprint)
        {
            this.ipAddress = ipAddress;
            this.username  = username;
            this.password  = password;
            this.ssh_host_key_fingerprint = ssh_host_key_fingerprint;

            this.session        = null;
            this.sessionOptions = null;
        }
Exemplo n.º 3
0
    private bool connect()
    {
        try
        {
            this.sessionOptions = new WinSCP.SessionOptions
            {
                Protocol              = WinSCP.Protocol.Sftp,
                PortNumber            = this.port,
                HostName              = this.ipAddress,
                UserName              = this.username,
                Password              = this.password,
                SshHostKeyFingerprint = this.ssh_host_key_fingerprint
            };

            this.session = new WinSCP.Session();
            this.session.Open(this.sessionOptions);
            return(true);
        }
        catch (Exception e) { Console.WriteLine(e.ToString()); return(false); }
    }
Exemplo n.º 4
0
        private bool UploadToFtp(string filename)
        {
            try
            {
                var sessionOptions = new WinSCP.SessionOptions
                {
                    FtpSecure  = WinSCP.FtpSecure.None,
                    Protocol   = WinSCP.Protocol.Ftp,
                    HostName   = ConfigurationManager.AppSettings["FTPHost"],
                    PortNumber = int.Parse(ConfigurationManager.AppSettings["FTPPort"]),
                    UserName   = ConfigurationManager.AppSettings["FTPUsername"],
                    Password   = ConfigurationManager.AppSettings["FTPPassword"],
                };
                string ftpRoot = ConfigurationManager.AppSettings["FTPRoot"];
                using (var session = new WinSCP.Session())
                {
                    session.Open(sessionOptions);
                    Log("Connected successfully to FTP server");
                    var transferOptions = new WinSCP.TransferOptions()
                    {
                        TransferMode = WinSCP.TransferMode.Binary
                    };

                    //Ceheck and create folder
                    String mftpFilePath = string.Format("/{0}/{1}年/{2}月/{3}/{4}.pdf", ftpRoot, DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.ToString("yyyyMMddHHmmss"));
                    //session.CreateDirectory(Constants.FTPRoot);

                    FileInfo fi      = new FileInfo(filename);
                    var      hResult = session.PutFiles(fi.FullName, mftpFilePath, false, transferOptions);
                    hResult.Check();
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }