代码之家  ›  专栏  ›  技术社区  ›  Nils Pipenbrinck

如何将文件上载到C(.NET)中的SFTP服务器?[关闭]

  •  63
  • Nils Pipenbrinck  · 技术社区  · 16 年前

    是否存在免费的.NET库,我可以使用它将文件上载到SFTP(ssh ftp)服务器,该服务器会在上载出现问题时引发异常,并允许监视其进度?

    5 回复  |  直到 6 年前
        1
  •  35
  •   Aaron Milan Rakos    8 年前

    也许你可以编写脚本/控制 winscp ?

    更新: WinSCP现在有 a .NET library 可用作 nuget package 支持SFTP、SCP和FTPS的

        2
  •  7
  •   Martin Vobr    14 年前

    下面的代码演示如何使用 Rebex SFTP 组件。

    // create client, connect and log in 
    Sftp client = new Sftp();
    client.Connect(hostname);
    client.Login(username, password);
    
    // upload the 'test.zip' file to the current directory at the server 
    client.PutFile(@"c:\data\test.zip", "test.zip");
    
    client.Disconnect();
    

    您可以使用logwriter属性将完整的通信日志写入文件,如下所示。可以找到示例输出(来自ftp组件,但sftp输出类似) here .

    client.LogWriter = new Rebex.FileLogWriter(
       @"c:\temp\log.txt", Rebex.LogLevel.Debug); 
    

    或使用以下事件拦截通信:

    Sftp client = new Sftp();
    client.CommandSent += new SftpCommandSentEventHandler(client_CommandSent);
    client.ResponseRead += new SftpResponseReadEventHandler(client_ResponseRead);
    client.Connect("sftp.example.org");
    
    //... 
    private void client_CommandSent(object sender, SftpCommandSentEventArgs e)
    {
        Console.WriteLine("Command: {0}", e.Command);
    }
    
    private void client_ResponseRead(object sender, SftpResponseReadEventArgs e)
    {
        Console.WriteLine("Response: {0}", e.Response);
    }
    

    有关详细信息,请参见 tutorial download 试一试 samples .

        3
  •  2
  •   ddc0660    16 年前

    在.NET框架中没有解决方案。

    http://www.eldos.com/sbb/sftpcompare.php 列出一个非自由选项列表。

    最好的免费方法是使用granados扩展ssh。 http://www.routrek.co.jp/en/product/varaterm/granados.html

        4
  •  0
  •   Mike L    16 年前

    不幸的是,它不在.NET框架中。我的愿望是您可以与filezilla集成,但我认为它不会公开接口。我认为他们确实有脚本,但显然不会那么干净。

    我在一个做sftp的项目中使用了cuteftp。它公开了一个com组件,我创建了一个.net包装器。你会发现,关键是权限。它在安装了cuteftp的windows凭据下运行得很好,但是在其他凭据下运行需要在dcom中设置权限。

        5
  •  0
  •   Bruce Blackshaw    15 年前

    另一个不自由的选择 edtFTPnet/PRO . 它全面支持sftp,如果需要还支持ftps(当然还有ftp)。