Renci.SshNet.SftpClient.DownloadFile C# (CSharp) Method

DownloadFile() public method

Downloads remote file specified by the path into the stream.
Method calls made by this method to output, may under certain conditions result in exceptions thrown by the stream.
is null. is null or contains only whitespace characters. Client is not connected. Permission to perform the operation was denied by the remote host. -or- A SSH command was denied by the server. was not found on the remote host. A SSH error where is the message from the remote host. The method was called after the client was disposed.
public DownloadFile ( string path, Stream output, Action downloadCallback = null ) : void
path string File to download.
output Stream Stream to write the file into.
downloadCallback Action The download callback.
return void
        public void DownloadFile(string path, Stream output, Action<ulong> downloadCallback = null)
        {
            CheckDisposed();

            InternalDownloadFile(path, output, null, downloadCallback);
        }

Usage Example

Beispiel #1
11
        public static void CopyFileFromRemoteToLocal(string host, string user, string password, string localPath, string remotePath)
        {
            using (SftpClient client = new SftpClient(host, user, password))
            {
                client.KeepAliveInterval = TimeSpan.FromSeconds(60);
                client.ConnectionInfo.Timeout = TimeSpan.FromMinutes(180);
                client.OperationTimeout = TimeSpan.FromMinutes(180);
                client.Connect();
                bool connected = client.IsConnected;
                // RunCommand(host, user, password, "sudo chmod 777 -R " + remotePath);
                var file = File.OpenWrite(localPath);
                client.DownloadFile(remotePath, file);

                file.Close();
                client.Disconnect();
            }
        }
All Usage Examples Of Renci.SshNet.SftpClient::DownloadFile