How to communicate with SFTP server

后端 未结 7 1518
谎友^
谎友^ 2021-02-14 01:48

I\'ve written a service for our customer that automatically transmits files to given destinations using FTP. For historic reasons I\'m using WinInet to perform the FTPing. All w

7条回答
  •  长情又很酷
    2021-02-14 02:13

    the .NET Framwork supports FTP via the FtpWebRequest since version 2.0. No support for SFTP yet.

    If you need both FTP and SFTP you have to try a third party component. There is an open source implementation of SFTP from Tamir Gal which is often recommended. Or you can try one of commercial SFTP components such as our Rebex SFTP.

    Following code is taken from Rebex SFTP tutorial page:

    // create client, connect and log in 
    Sftp client = new Sftp();
    client.Connect(hostname);
    client.Login(username, password);
    
    // upload the content of 'c:\data' directory and all subdirectories 
    // to the '/wwwroot' directory at the server 
    client.PutFiles(@"c:\data\*", "/wwwroot", SftpBatchTransferOptions.Recursive);
    
    client.Disconnect();
    

    If you are not sure whether you will need FTPS or SFTP you can check the Rebex File Transfer Pack which includes both. The FTP API is almost identical to the SFTP one.

提交回复
热议问题