当前位置: 首页>>代码示例>>C#>>正文


C# SftpClient.BeginUploadFile方法代码示例

本文整理汇总了C#中SftpClient.BeginUploadFile方法的典型用法代码示例。如果您正苦于以下问题:C# SftpClient.BeginUploadFile方法的具体用法?C# SftpClient.BeginUploadFile怎么用?C# SftpClient.BeginUploadFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SftpClient的用法示例。


在下文中一共展示了SftpClient.BeginUploadFile方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Test_Sftp_BeginUploadFile_StreamIsNull

 public void Test_Sftp_BeginUploadFile_StreamIsNull()
 {
     using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
     {
         sftp.Connect();
         sftp.BeginUploadFile(null, "aaaaa", null, null);
         sftp.Disconnect();
     }
 }
开发者ID:pecegit,项目名称:sshnet,代码行数:9,代码来源:SftpClientTest.Upload.cs

示例2: Test_Sftp_BeginUploadFile_FileNameIsWhiteSpace

 public void Test_Sftp_BeginUploadFile_FileNameIsWhiteSpace()
 {
     using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
     {
         sftp.Connect();
         sftp.BeginUploadFile(new MemoryStream(), "   ", null, null);
         sftp.Disconnect();
     }
 }
开发者ID:pecegit,项目名称:sshnet,代码行数:9,代码来源:SftpClientTest.Upload.cs

示例3: Test_Sftp_EndUploadFile_Invalid_Async_Handle

 public void Test_Sftp_EndUploadFile_Invalid_Async_Handle()
 {
     using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
     {
         sftp.Connect();
         var async1 = sftp.BeginListDirectory("/", null, null);
         var filename = Path.GetTempFileName();
         this.CreateTestFile(filename, 100);
         var async2 = sftp.BeginUploadFile(File.OpenRead(filename), "test", null, null);
         sftp.EndUploadFile(async1);
     }
 }
开发者ID:pecegit,项目名称:sshnet,代码行数:12,代码来源:SftpClientTest.Upload.cs

示例4: Test_Sftp_Ensure_Async_Delegates_Called_For_BeginFileUpload_BeginFileDownload_BeginListDirectory

        public void Test_Sftp_Ensure_Async_Delegates_Called_For_BeginFileUpload_BeginFileDownload_BeginListDirectory()
        {
            using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
            {
                sftp.Connect();

                string remoteFileName = Path.GetRandomFileName();
                string localFileName = Path.GetRandomFileName();
                bool uploadDelegateCalled = false;
                bool downloadDelegateCalled = false;
                bool listDirectoryDelegateCalled = false;
                IAsyncResult asyncResult;

                // Test for BeginUploadFile.

                CreateTestFile(localFileName, 1);

                using (var fileStream = File.OpenRead(localFileName))
                {
                    asyncResult = sftp.BeginUploadFile(fileStream, remoteFileName, delegate(IAsyncResult ar)
                    {
                        sftp.EndUploadFile(ar);
                        uploadDelegateCalled = true;
                    }, null);

                    while (!asyncResult.IsCompleted)
                    {
                        Thread.Sleep(500);
                    }
                }

                File.Delete(localFileName);

                Assert.IsTrue(uploadDelegateCalled, "BeginUploadFile");

                // Test for BeginDownloadFile.

                asyncResult = null;
                using (var fileStream = File.OpenWrite(localFileName))
                {
                    asyncResult = sftp.BeginDownloadFile(remoteFileName, fileStream, delegate(IAsyncResult ar)
                    {
                        sftp.EndDownloadFile(ar);
                        downloadDelegateCalled = true;
                    }, null);

                    while (!asyncResult.IsCompleted)
                    {
                        Thread.Sleep(500);
                    }
                }

                File.Delete(localFileName);

                Assert.IsTrue(downloadDelegateCalled, "BeginDownloadFile");

                // Test for BeginListDirectory.

                asyncResult = null;
                asyncResult = sftp.BeginListDirectory(sftp.WorkingDirectory, delegate(IAsyncResult ar)
                {
                    sftp.EndListDirectory(ar);
                    listDirectoryDelegateCalled = true;
                }, null);

                while (!asyncResult.IsCompleted)
                {
                    Thread.Sleep(500);
                }

                Assert.IsTrue(listDirectoryDelegateCalled, "BeginListDirectory");
            }
        }
开发者ID:pecegit,项目名称:sshnet,代码行数:73,代码来源:SftpClientTest.Upload.cs

示例5: Test_Sftp_Multiple_Async_Upload_And_Download_10Files_5MB_Each

        public void Test_Sftp_Multiple_Async_Upload_And_Download_10Files_5MB_Each()
        {
            var maxFiles = 10;
            var maxSize = 5;

            using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
            {
                sftp.Connect();

                var testInfoList = new Dictionary<string, TestInfo>();

                for (int i = 0; i < maxFiles; i++)
                {
                    var testInfo = new TestInfo();
                    testInfo.UploadedFileName = Path.GetTempFileName();
                    testInfo.DownloadedFileName = Path.GetTempFileName();
                    testInfo.RemoteFileName = Path.GetRandomFileName();

                    this.CreateTestFile(testInfo.UploadedFileName, maxSize);

                    //  Calculate hash value
                    testInfo.UploadedHash = CalculateMD5(testInfo.UploadedFileName);

                    testInfoList.Add(testInfo.RemoteFileName, testInfo);
                }

                var uploadWaitHandles = new List<WaitHandle>();

                //  Start file uploads
                foreach (var remoteFile in testInfoList.Keys)
                {
                    var testInfo = testInfoList[remoteFile];
                    testInfo.UploadedFile = File.OpenRead(testInfo.UploadedFileName);

                    testInfo.UploadResult = sftp.BeginUploadFile(testInfo.UploadedFile,
                        remoteFile,
                        null,
                        null) as SftpUploadAsyncResult;

                    uploadWaitHandles.Add(testInfo.UploadResult.AsyncWaitHandle);
                }

                //  Wait for upload to finish
                bool uploadCompleted = false;
                while (!uploadCompleted)
                {
                    //  Assume upload completed
                    uploadCompleted = true;

                    foreach (var testInfo in testInfoList.Values)
                    {
                        var sftpResult = testInfo.UploadResult;

                        if (!testInfo.UploadResult.IsCompleted)
                        {
                            uploadCompleted = false;
                        }
                    }
                    Thread.Sleep(500);
                }

                //  End file uploads
                foreach (var remoteFile in testInfoList.Keys)
                {
                    var testInfo = testInfoList[remoteFile];

                    sftp.EndUploadFile(testInfo.UploadResult);
                    testInfo.UploadedFile.Dispose();
                }

                //  Start file downloads

                var downloadWaitHandles = new List<WaitHandle>();

                foreach (var remoteFile in testInfoList.Keys)
                {
                    var testInfo = testInfoList[remoteFile];
                    testInfo.DownloadedFile = File.OpenWrite(testInfo.DownloadedFileName);
                    testInfo.DownloadResult = sftp.BeginDownloadFile(remoteFile,
                        testInfo.DownloadedFile,
                        null,
                        null) as SftpDownloadAsyncResult;

                    downloadWaitHandles.Add(testInfo.DownloadResult.AsyncWaitHandle);
                }

                //  Wait for download to finish
                bool downloadCompleted = false;
                while (!downloadCompleted)
                {
                    //  Assume download completed
                    downloadCompleted = true;

                    foreach (var testInfo in testInfoList.Values)
                    {
                        var sftpResult = testInfo.DownloadResult;

                        if (!testInfo.DownloadResult.IsCompleted)
                        {
                            downloadCompleted = false;
//.........这里部分代码省略.........
开发者ID:pecegit,项目名称:sshnet,代码行数:101,代码来源:SftpClientTest.Upload.cs

示例6: UploadFilesFromFilemanager

                private void UploadFilesFromFilemanager()
                {
                    string destpathroot = txtRemoteFolderPath.Text;
                    if (!destpathroot.EndsWith("/"))
                    {
                        destpathroot += "/";
                    }
                    var filelist = new Dictionary<string, string>();
                    foreach (var item in lvLocalBrowser.SelectedItems.Cast<EXImageListViewItem>().Where(item => (string) item.Tag != "[..]"))
                    {
                        if ((string)item.Tag == "File")
                        {
                            filelist.Add(item.MyValue, destpathroot + Path.GetFileName(item.MyValue));
                        }
                        if ((string)item.Tag == "Folder")
                        {
                            string folder = Path.GetDirectoryName(item.MyValue);
                            folder = folder.EndsWith("\\") ? folder : folder + "\\";
                            string[] files = Directory.GetFiles(item.MyValue,
                                                                "*.*",
                                                                SearchOption.AllDirectories);

                            // Display all the files.
                            foreach (string file in files)
                            {
                                filelist.Add(Path.GetFullPath(file), destpathroot + Path.GetFullPath(file).Replace(folder,"").Replace("\\","/"));
                            }
                        }
                    }
                    long fulllength = filelist.Sum(file => new FileInfo(file.Key).Length);
                    MessageBox.Show(Tools.Misc.LengthToHumanReadable(fulllength));
                    var ssh = new SftpClient(txtHost.Text, int.Parse(this.txtPort.Text), txtUser.Text, txtPassword.Text);
                    ssh.Connect();

                    ThreadPool.QueueUserWorkItem(state =>
                        {
                            long totaluploaded = 0;
                            foreach (var file in filelist)
                            {
                                CreatSSHDir(ssh, file.Value);
                                var s = new FileStream(file.Key, FileMode.Open);
                                var i = ssh.BeginUploadFile(s, file.Value) as SftpUploadAsyncResult;
                                while (!i.IsCompleted)
                                {
                                    SetProgressStatus(totaluploaded + (long)i.UploadedBytes, fulllength);
                                }
                                ssh.EndUploadFile(i);
                                totaluploaded += s.Length;
                            }
                            MessageBox.Show(Language.SSHTransfer_StartTransfer_Upload_completed_);
                            EnableButtons();
                            ssh.Disconnect();
                        });
                }
开发者ID:jpmarques,项目名称:mRemoteNC,代码行数:54,代码来源:UI.Window.SSHTransfer.cs

示例7: StartTransfer

                private void StartTransfer(SSHTransferProtocol Protocol)
                {
                    if (AllFieldsSet() == false)
                    {
                        Runtime.MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg,
                                                            Language.strPleaseFillAllFields);
                        return;
                    }

                    if (File.Exists(this.txtLocalFile.Text) == false)
                    {
                        Runtime.MessageCollector.AddMessage(Messages.MessageClass.WarningMsg,
                                                            Language.strLocalFileDoesNotExist);
                        return;
                    }

                    try
                    {
                        if (Protocol == SSHTransferProtocol.SCP)
                        {
                            var ssh = new ScpClient(txtHost.Text, int.Parse(this.txtPort.Text), txtUser.Text, txtPassword.Text);
                            ssh.Uploading+=(sender, e) => SetProgressStatus(e.Uploaded, e.Size);
                            DisableButtons();
                            ssh.Connect();
                            ssh.Upload(new FileStream(txtLocalFile.Text,FileMode.Open), txtRemoteFile.Text);
                        }
                        else if (Protocol == SSHTransferProtocol.SFTP)
                        {
                            var ssh = new SftpClient(txtHost.Text, int.Parse(txtPort.Text),txtUser.Text, txtPassword.Text);
                            var s = new FileStream(txtLocalFile.Text, FileMode.Open);
                            ssh.Connect();
                            var i = ssh.BeginUploadFile(s, txtRemoteFile.Text) as SftpUploadAsyncResult;
                            ThreadPool.QueueUserWorkItem(state =>
                            {
                                while (!i.IsCompleted)
                                {
                                    SetProgressStatus((long)i.UploadedBytes, s.Length);
                                }
                                MessageBox.Show(Language.SSHTransfer_StartTransfer_Upload_completed_);
                                EnableButtons();
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        Runtime.MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg,
                                                            Language.strSSHTransferFailed + Constants.vbNewLine +
                                                            ex.Message);
                        EnableButtons();
                    }
                }
开发者ID:jpmarques,项目名称:mRemoteNC,代码行数:51,代码来源:UI.Window.SSHTransfer.cs

示例8: BeginUploadFileTest1

 public void BeginUploadFileTest1()
 {
     ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value
     SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value
     Stream input = null; // TODO: Initialize to an appropriate value
     string path = string.Empty; // TODO: Initialize to an appropriate value
     bool canOverride = false; // TODO: Initialize to an appropriate value
     AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value
     object state = null; // TODO: Initialize to an appropriate value
     Action<ulong> uploadCallback = null; // TODO: Initialize to an appropriate value
     IAsyncResult expected = null; // TODO: Initialize to an appropriate value
     IAsyncResult actual;
     actual = target.BeginUploadFile(input, path, canOverride, asyncCallback, state, uploadCallback);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
开发者ID:pecegit,项目名称:sshnet,代码行数:16,代码来源:SftpClientTest.cs


注:本文中的SftpClient.BeginUploadFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。