1

Is there a way to robocopy and pipeline Get-Credential? I am trying to copy a file over to a window server for my workplace which requires my credentials

I saw things like subprocess and tried that but can't seem to call Get-Credential to input my creds.

powershell = "robocopy " + Migration_data_csv + " " + destination + "/S | Get-Credential"
ps = subprocess.Popen(powershell,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)

I end up getting an error when I try to pipe the command Get-Credential

b"'Get-Credential' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n"

If not is there a way for me to copy a file over to a window server? I also tried FTP via ftplib but the window server refuse the connection.

David Brabant
  • 41,623
  • 16
  • 83
  • 111

1 Answers1

1

Is there a way to robocopy and pipeline Get-Credential?

No. These commands are not designed to work together. Robocopy.exe relies on the process that starts it already having the correct permissions. Get-Credential does not work in a pipeline like that, either.

I also tried FTP via ftplib but the window server refuse the connection.

Correct. FTP does not run on most systems, Windows or otherwise. It's a deprecated transfer protocol.

Windows does not run an SSH daemon by default, either, so SFTP is not available.

If not is there a way for me to copy a file over to a window server?

You could try mounting the remote share or starting a process as the correct user and then copying the file.

Truthfully, however, the Microsoft way to do this is to ensure that the user account running the process is one that already has access to the remote share and file. Then either map the drive and use filesystem tools or access the share with a Python SMB/CIFS library. Or call RoboCopy.

Bacon Bits
  • 30,782
  • 5
  • 59
  • 66