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

ChangeDirectory() public method

Changes remote directory to path.
is null. Client is not connected. Permission to change directory denied by 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 ChangeDirectory ( string path ) : void
path string New directory path.
return void
        public void ChangeDirectory(string path)
        {
            CheckDisposed();

            if (path == null)
                throw new ArgumentNullException("path");

            if (_sftpSession == null)
                throw new SshConnectionException("Client not connected.");

            _sftpSession.ChangeDirectory(path);
        }

Usage Example

 public bool UploadFile(string filePath)
 {
     ConnectionInfo connectionInfo = new PasswordConnectionInfo(_address, ConstFields.SFTP_PORT, _username, _password);
     try
     {
         using (var sftp = new SftpClient(connectionInfo))
         {
             sftp.Connect();
             using (var file = File.OpenRead(filePath))
             {
                 if (!sftp.Exists(ConstFields.TEMP_PRINT_DIRECTORY))
                 {
                     sftp.CreateDirectory(ConstFields.TEMP_PRINT_DIRECTORY);
                 }
                 sftp.ChangeDirectory(ConstFields.TEMP_PRINT_DIRECTORY);
                 string filename = Path.GetFileName(filePath);
                 sftp.UploadFile(file, filename);
             }
             sftp.Disconnect();
         }
     }
     catch (Renci.SshNet.Common.SshConnectionException)
     {
         Console.WriteLine("Cannot connect to the server.");
         return false;
     }
     catch (System.Net.Sockets.SocketException)
     {
         Console.WriteLine("Unable to establish the socket.");
         return false;
     }
     catch (Renci.SshNet.Common.SshAuthenticationException)
     {
         Console.WriteLine("Authentication of SSH session failed.");
         return false;
     }
     return true;
 }
All Usage Examples Of Renci.SshNet.SftpClient::ChangeDirectory