Пример #1
0
        // 连接SFTP
        public SFtpClient connSftp(Server server)
        {
            SFtpClient ftp = new SFtpClient(server.Ip, server.SftpPort, server.OsUser, server.OsPassword);

            ftp.Connect();
            return(ftp);
        }
Пример #2
0
        public void FTPsTestWithoutFingerPrint()
        {
            var ftpS   = new SFtpClient("localhost", "admin", "syncplify", FtpSecure.Explicit);
            var result = ftpS.FtpUpload(@"d:\temp\test2.csv", "/");

            // assert
            result.IsSuccess.Should().BeTrue();
            result.Transfers.Count.Should().Be(1);
            result.Transfers.First().FileName.Should().BeEquivalentTo(@"d:\temp\test2.csv");
        }
Пример #3
0
        public void FTPTest()
        {
            var ftp    = new SFtpClient("localhost", "admin", "syncplify", FtpSecure.None);
            var result = ftp.FtpUpload(@"d:\temp\test1.csv", "/");

            // assertsync
            result.IsSuccess.Should().BeTrue();
            result.Transfers.Count.Should().Be(1);
            result.Transfers.First().FileName.Should().BeEquivalentTo(@"d:\temp\test1.csv");
        }
Пример #4
0
        public void FTPsTestWithFingerPrint()
        {
            var ftpS   = new SFtpClient("localhost", "admin", "syncplify", FtpSecure.Explicit, "68:8c:12:46:ce:0b:2c:d3:63:95:45:b6:26:d2:ec:b9:cb:72:18:77");
            var result = ftpS.FtpUpload(@"d:\temp\test3.csv", "/");

            // assert
            result.IsSuccess.Should().BeTrue();
            result.Transfers.Count.Should().Be(1);
            result.Transfers.First().FileName.Should().BeEquivalentTo(@"d:\temp\test3.csv");
        }
Пример #5
0
        // 查询项目日志
        public List <FtpFile> getProjectLogFiles(int projectId)
        {
            Project prj    = projectDAO.findProject(projectId);
            Server  server = prj.Server;

            SFtpClient     ftp      = serverService.connSftp(server);
            List <FtpFile> logFiles = ftp.getFileList(prj.LogPath);

            return(logFiles);
        }
Пример #6
0
        public void SFtpClientTest()
        {
            SFtpClient ftp = new SFtpClient("127.0.0.1", 22, "root", "123456");

            ftp.Connect();
            List <FtpFile> files = ftp.getFileList("/");

            Console.WriteLine("file count:" + files.ToArray().Length);
            foreach (FtpFile f in files)
            {
                Console.WriteLine(f.fullname);
            }
        }
Пример #7
0
        public void SFtpClientTestDownload()
        {
            SFtpClient ftp = new SFtpClient("127.0.0.1", 22, "root", "123456");

            ftp.Connect();
            List <FtpFile> files = ftp.getFileList("/logs/");

            Console.WriteLine("file count:" + files.ToArray().Length);
            foreach (FtpFile f in files)
            {
                Console.WriteLine(f.fullname);
                if (!f.isDirectory)
                {
                    DownloadAsyncResult result   = new DownloadAsyncResult(1, 1);
                    AsyncCallback       callback = new AsyncCallback(DownloadCallBack);
                    ftp.DownloadFile(f.fullname, "E:\\" + f.name, callback);

                    Console.WriteLine("download completeed!");
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Send file over non secure FTP
        /// </summary>
        public void SendSftp()
        {
            var sftpClient = new SFtpClient(new SessionOptions(), "hostname", "username", "password", Protocol.Ftp);

            sftpClient.FtpUpload("localPath", "remotePath");
        }