você precisa apenas de dois comandos
- use
net use
para conectar um recurso compartilhado - use
xcopy
para copiar arquivos
script de exemplo:
net use z: \some_host\$c secret_password /user:some_domain\some_user
md g:\xc
xcopy z:*.mp3 g:\xc\ /E /C /I /G /H /Z /B
xcopy z:*.wav g:\xc\ /E /C /I /G /H /Z /B
xcopy z:*.mp4 g:\xc\ /E /C /I /G /H /Z /B
onde os parâmetros net use
são:
z: - some free drive letter
\some_host\$c - default windows C:\ share on some_host in your network
/user: - user that have access to this share
secret_password - this user password
onde os parâmetros xcopy
são:
z:*.mp3 Source and file mask
g:\xc\ Destination
/E Copies directories and subdirectories, including empty ones.
/C Continues copying even if errors occur.
/I If destination does not exist and copying more than one file,
assumes that destination must be a directory.
/G Allows the copying of encrypted files to destination that does
not support encryption.
/H Copies hidden and system files also.
/Z Copies networked files in restartable mode.
/B Copies the Symbolic Link itself versus the target of the link.
você pode copiar de maneira inversa em todos os computadores do domínio atual usando psexec se você especificar um curinga ( \*
) como computador
psexec \* -u some_domain\some_user -p secret_password -h -c script.cmd
onde
-u Specifies optional user name for login to remote
computer.
-p Specifies optional password for user name. If you omit this
you will be prompted to enter a hidden password.
-h If the target system is Vista or higher, has the process
run with the account's elevated token, if available.
-c Copy the specified program to the remote system for
execution. If you omit this option the application
must be in the system path on the remote system.
exemplo script.cmd
:
net use z: \your_host\some_share
xcopy c:*.mp3 z:\ /E /C /I /G /H /Z /B /R /Y
net use z: /delete
onde você deve usar parâmetros adicionais:
/R Overwrites read-only files.
/Y Suppresses prompting to confirm you want to overwrite an
existing destination file.