Renci.SshNet.Sftp.SftpFile.MoveTo C# (CSharp) Method

MoveTo() public method

Moves a specified file to a new location on remote machine, providing the option to specify a new file name.
is null.
public MoveTo ( string destFileName ) : void
destFileName string The path to move the file to, which can specify a different file name.
return void
        public void MoveTo(string destFileName)
        {
            if (destFileName == null)
                throw new ArgumentNullException("destFileName");
            _sftpSession.RequestRename(FullName, destFileName);

            var fullPath = _sftpSession.GetCanonicalPath(destFileName);

            Name = fullPath.Substring(fullPath.LastIndexOf('/') + 1);

            FullName = fullPath;
        }

Usage Example

Example #1
0
 public void MoveToTest()
 {
     SftpSession sftpSession = null; // TODO: Initialize to an appropriate value
     string fullName = string.Empty; // TODO: Initialize to an appropriate value
     SftpFileAttributes attributes = null; // TODO: Initialize to an appropriate value
     SftpFile target = new SftpFile(sftpSession, fullName, attributes); // TODO: Initialize to an appropriate value
     string destFileName = string.Empty; // TODO: Initialize to an appropriate value
     target.MoveTo(destFileName);
     Assert.Inconclusive("A method that does not return a value cannot be verified.");
 }