Jump to content

[SOLVED] Help with file copy from remote server


Recommended Posts

Hello from Barcelona.

 

I'm working in a script that fills some pdf files with some strings of text. The main problem that I have is that the last and updated version of these files is in the server of our company.

As some old files might get an update, I do always need to get the latest version of the files (just one single pdf for every time that the script is executed.

I've been reading and surfing int he forum for examples for this kind of remote file copying, but none of them has worked for me.

I know that I can acces to the server because thanks to one of those examples I can connect in a RDP conecction.

The RDP connection script is this one:

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <AutoItConstants.au3>

$oRDP = ObjCreate("MsTscAx.MsTscAx")
$gui = GUICreate("RDP", 800, 800, 0, -1, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
GUISetState(@SW_HIDE, $gui)
$GUIActiveX = GUICtrlCreateObj($oRDP, 0, 0, 800, 800)
GUICtrlSetStyle($GUIActiveX, $WS_VISIBLE)
GUICtrlSetResizing($GUIActiveX, $GUI_DOCKAUTO)

GUISetState()

$oRDP.Server = "192.168.20.61" ;NetBIOS, DNS oder IP des Gerätes
$oRDP.Domain = "FILESERVER" ;Anmeldedomäne (Rechnername oder NetBIOS Domänenname)
$oRDP.UserName = "companyname1\user" ; Benutzername
$oRDP.AdvancedSettings2.ClearTextPassword = "XXXXX-XXXXX-XXXXX" ; das Passwort dazu
$oRDP.FullScreen = False ; Vollbild ja/nein - hat nichts mit der Auflösung zu tun
$oRDP.AdvancedSettings2.RedirectDrives = True ; Sollen die Laufwerke mitgenommen werden
$oRDP.AdvancedSettings2.RedirectPrinters = False ; Sollen die Drucker mitgenommen werden
$oRDP.AdvancedSettings2.RedirectPorts = False ; Ports wie LPT1 etc
$oRDP.AdvancedSettings2.RedirectSmartCards = False ; SmartCards für Authentifizierung
$oRDP.ConnectingText = "Conectando ...." ; Text der erscheint bevor das Bild des Servers erscheint
; Nachfolgende Zeilen von eigenen Test's - ich musste mal das mit den "AdvancedSettings2" 3 4 etc. ausklingeln
$oRDP.AdvancedSettings2.EnableAutoReconnect = True
$oRDP.AdvancedSettings2.allowBackgroundInput = True
$oRDP.AdvancedSettings2.ConnectionBarShowRestoreButton = True
$oRDP.AdvancedSettings5.AudioRedirectionMode = 0

$oRDP.Connect()


ObjEvent($oRDP, 'rdpevent_')

Func rdpevent_OnLoginComplete()
    ConsoleWrite('loging complete' & @CRLF)

    ; copy()
EndFunc   ;==>rdpevent_OnLoginComplete



Func copiar()
    $remoteclient = "192.168.20.61"
    $Domain = "FILESERVER"
    $Username = "companyname1\user"
    $Password = "XXXXX-XXXXX-XXXXX"


    ; Map X drive to \\myserver\stuff using current user
    ;DriveMapAdd("X:", "\\myserver\stuff")
    ;RunAsWait("companyname1\user","FILESERVER","XXXXX-XXXXX-XXXXX", 0, @ComSpec & ' /c ' & 'copy "\\192.168.20.61\X$\a.txt, "C:\Users\Mantenimiento\Desktop\"', "", @SW_HIDE)
    ; Map X drive to \\myserver2\stuff2 using the user "jon" from "domainx" with password "tickle"
    DriveMapAdd("X:", "A:", 0, "companyname1\user", "XXXXX-XXXXX-XXXXX")
    ConsoleWrite("error " & @error)


EndFunc   ;==>copiar

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd
GUIDelete()
Exit
  ;==>

Doing this I get this GUI with the Remote Computer:

Sin+t%25C3%25ADtulo.png

The folder with the pdf files is the one marked.

Looking at the remote computer hard disk drives folder I get this:

fallo.png

The hdd where the pdf files are is a Network location. I don't know if this is a problem to get the files copied from the remote computer to the local one. I have zero knowledge about networks. :sweating:

Any idea or help would be really apreciatted.

Edited by Qwerty212
Link to comment
Share on other sites

  • Moderators

Does your local computer have access to that network share? If so, it seems a lot less hassle to grab files from the share from your local PC, rather than connecting to the remote machine, then out to the network share.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

So I would write a script that pulls the file to a spot local on the remote machine (tempdir, perhaps). Then use PSExec to run the script on the remote machine. When you've made your changes you would need to run a script on the remote computer to upload the file back to the share.

How are you logging into the remote machine, with your network credentials or with another account?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

All of that is to ensure he can RDP, which the OP already stated that he can. It doesn't resolve the issue of the man-in-the-middle filecopy he is attempting.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

1 hour ago, JLogan3o13 said:

So I would write a script that pulls the file to a spot local on the remote machine (tempdir, perhaps). Then use PSExec to run the script on the remote machine. When you've made your changes you would need to run a script on the remote computer to upload the file back to the share.

How are you logging into the remote machine, with your network credentials or with another account?

Thanks for the PSExec hint, I've to look for some info and examples about this.

 

I rarely log into the remote machine. Just when I manually copy one of the pdf to the local machine to code a script that fills it. But when I have to logging I use the user and the password to the server. I don't need to login in the local machine.

Link to comment
Share on other sites

If you have the username/password to RDP and you can access the shared path when logged in, then you can map or connect to the remote share using that username/password.  For example:
nb: You need to check the spelling of Publica it appears to have an accent which I'm unfamiliar with.

DriveMapAdd('X:', '\\DATOS1\Compartida\Publica', 1, 'Domain\Username', 'Password') ;~ Map the drive to the server share
FileCopy('X:\PAUTAS', 'C:\Data\', 9) ;~ Copy the folder X:\PAUTAS to C:\Data, Create the folder path if it doesn't exist.
DriveMapDel('X:') ;~ Delete the Mapped Drive; Optional you can delete this if you prefer to keep the mapped drive.

It appears that you have a function in your script above but it's incorrectly formatted i.e. "DriveMapAdd('X:', 'A:'...".  The A: should be a shared path, on top of that the function is never called. in the script.

Link to comment
Share on other sites

  • Moderators
9 minutes ago, Qwerty212 said:

But when I have to logging I use the user and the password to the server.

What I am trying to get at (I think there is a translation breakdown), is the type of account you log into the server with. It is an Active Directory account or an account local to the server? If it is the former, then the suggestion by Subz will work. If it is the latter, it will not (which is why I was trying to confirm).

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

21 minutes ago, Subz said:

If you have the username/password to RDP and you can access the shared path when logged in, then you can map or connect to the remote share using that username/password.  For example:
nb: You need to check the spelling of Publica it appears to have an accent which I'm unfamiliar with.

DriveMapAdd('X:', '\\DATOS1\Compartida\Publica', 1, 'Domain\Username', 'Password') ;~ Map the drive to the server share
FileCopy('X:\PAUTAS', 'C:\Data\', 9) ;~ Copy the folder X:\PAUTAS to C:\Data, Create the folder path if it doesn't exist.
DriveMapDel('X:') ;~ Delete the Mapped Drive; Optional you can delete this if you prefer to keep the mapped drive.

It appears that you have a function in your script above but it's incorrectly formatted i.e. "DriveMapAdd('X:', 'A:'...".  The A: should be a shared path, on top of that the function is never called. in the script.

Yes, it was one of the tests that I did. Thanks for your help. I tried but it didn't worked

13 minutes ago, JLogan3o13 said:

What I am trying to get at (I think there is a translation breakdown), is the type of account you log into the server with. It is an Active Directory account or an account local to the server? If it is the former, then the suggestion by Subz will work. If it is the latter, it will not (which is why I was trying to confirm).

I don't know, the Data Folder is created, but it didn't copy anything. ^_^ (we are closer)

Edited by Qwerty212
Link to comment
Share on other sites

  • Moderators

It could be a service account, and I have seen local accounts given access to network resources at some of my customers. Personally, I never assume.

@Qwerty212 can you please post a screen shot of the RDP screen showing the Username before you login to the server (not the password, just username)? There is some confusion on your part as to what type of account this is, and we cannot provide you the best assistance until we nail this down.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

13 minutes ago, JLogan3o13 said:

It could be a service account, and I have seen local accounts given access to network resources at some of my customers. Personally, I never assume.

@Qwerty212 can you please post a screen shot of the RDP screen showing the Username before you login to the server (not the password, just username)? There is some confusion on your part as to what type of account this is, and we cannot provide you the best assistance until we nail this down.

Sure:

Sin+t%25C3%25ADtulo.png

I have changed the company name for privacy reasons.

 

Link to comment
Share on other sites

  • Moderators

So it is a domain account. If that is the case, are you able to manually map a drive on your local machine, using the credentials for company.local\jaume? That would save you a step.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

15 hours ago, JLogan3o13 said:

So it is a domain account. If that is the case, are you able to manually map a drive on your local machine, using the credentials for company.local\jaume? That would save you a step.

I have to do some research and look for examples to do that. Thanks for the hint.

15 hours ago, Subz said:

If you open a command prompt

What is the result of:

Ping DATOS1

If that fails does pinging the fqdn work:

Ping DATOS1.Company.local

Just wondering if you have DNS issues which is why you're unable to map the drive.

Microsoft Windows [Versión 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. Reservados todos los derechos.

C:\Users\jaume>Ping DATOS1

Haciendo ping a DATOS1.company.local [192.168.20.13] con 32 bytes de datos:
Respuesta desde 192.168.20.13: bytes=32 tiempo<1m TTL=128
Respuesta desde 192.168.20.13: bytes=32 tiempo=1ms TTL=128
Respuesta desde 192.168.20.13: bytes=32 tiempo=2ms TTL=128
Respuesta desde 192.168.20.13: bytes=32 tiempo<1m TTL=128

Estadísticas de ping para 192.168.20.13:
    Paquetes: enviados = 4, recibidos = 4, perdidos = 0
    (0% perdidos),
Tiempos aproximados de ida y vuelta en milisegundos:
    Mínimo = 0ms, Máximo = 2ms, Media = 0ms

C:\Users\jaume>

Sorry, it's in Spanish, but I get this (running cmd in the rdp session)

In the local machine I get no response doing ping to DATOS1

Neither doing Ping DATOS1.Company.local

I'm sure that this is not what you've asked for and that I've done a stupid thing. Sorry. Networks are my pain in the ass. I barely know that Google's DNS are 8.8.8.8 and 4.4.4.4. That's it. That's all my networks knowledge :>

Greets from Barcelona

 

 

Edited by Qwerty212
Link to comment
Share on other sites

52 minutes ago, Subz said:

So from your local machine can you ping 192.168.20.13?

Yes, it works:

Microsoft Windows [Versión 10.0.14393]
(c) 2016 Microsoft Corporation. Todos los derechos reservados.

C:\Users\Mantenimiento>ping 192.168.20.13

Haciendo ping a 192.168.20.13 con 32 bytes de datos:
Respuesta desde 192.168.20.13: bytes=32 tiempo=118ms TTL=124
Respuesta desde 192.168.20.13: bytes=32 tiempo=49ms TTL=124
Respuesta desde 192.168.20.13: bytes=32 tiempo=35ms TTL=124
Respuesta desde 192.168.20.13: bytes=32 tiempo=59ms TTL=124

Estadísticas de ping para 192.168.20.13:
    Paquetes: enviados = 4, recibidos = 4, perdidos = 0
    (0% perdidos),
Tiempos aproximados de ida y vuelta en milisegundos:
    Mínimo = 35ms, Máximo = 118ms, Media = 65ms

C:\Users\Mantenimiento>

 

Link to comment
Share on other sites

So if you click Start » Run and type:
nb: Please rename Publica as I still don't know what accent is over the "u"

\\192.168.20.13\Compartida\Publica

Are you prompted for username and password, if yes when you enter your domain.local\username and password do you get access?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...