Jump to content

Recommended Posts

Posted

I am new to autoit and am trying to get a zipped file on my computer to download to a remote server. Is this possible with the filecopy() function? What is this best way to achieve this?

Posted (edited)

Filecopy to the unc path if you have permissions on your current user account to that server.

If not, map a drive, and then copy to that drive mapping.  DriveMapAdd

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Posted
16 hours ago, jdelaney said:

Filecopy to the unc path if you have permissions on your current user account to that server.

If not, map a drive, and then copy to that drive mapping.  DriveMapAdd

$user = InputBox("Security Check", "Enter your USERID.", "")
$password = InputBox("Security Check", "Enter your password.", "", "*")
   
Local $domain = "xxxxxx.com"
   
DriveMapDel("j:")
DriveMapAdd("j:", "\\xxxxxxxx\xxx\xxxxxx", 0, $domain & "\" & $user, $password)
FileCopy ( "C:\Users\user\Desktop\test.zip", "J:\Users\user\Desktop" [, flag = 0] )

I am getting the following error on the "FileCopy()" function:

Error: Subscript used on non-accessible variable.

 

What am I doing wrong?

  • Developers
Posted

You need to remove those [] from that last line as they are only in the helpfile to indicate an optional parameter, and specify just a value for the Flag or use the default 0. ;) 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted
1 minute ago, Jos said:

You need to remove those [] from that last line as they are only in the helpfile to indicate an optional parameter, and specify just a value for the Flag or use the default 0. ;) 

Jos

Thanks for the help. dumb mistake on my part. I removed it and added a "0". I am not getting an error anymore but I am not seeing the file being copied over.

Posted

You do not have any error checking your DriveMapAdd and FileCopy.  Here's snippet for you to work with.   

#include <WinAPIDlg.au3>

Global $sLocalPath = "C:\Users\user\Desktop\test.zip"
Global $sShare = "\\PC-NAME\c$"
Global $sSharePath = $sShare & "\Users\user\Desktop\"
Global $sDomain = "xxxxxx.com"
Global $sMappedDrive = ""
Global $sMsg = ""
Global $iMsgBoxAnswer = 0
Global $aUser[2] = ["", ""]

While True
    $aUser = _WinAPI_ShellUserAuthenticationDlgEx($sShare & " Share", "Enter your username and password for access.", $aUser[0], $aUser[1])
    If @error Then Exit
    
    If StringLeft($aUser[0], 3) <> $sDomain & "\" Then $aUser[0] = $sDomain & "\" & $aUser[0] 
    
    $sMappedDrive = DriveMapAdd("*", $sShare, 0, $aUser[0], $aUser[1])
    Switch @error
        Case 0
            $aUser = 0
            ExitLoop
        Case 2
            $sMsg = "Access to the remote share was denied."
        Case 3
            $sMsg = "The device is already assigned."
        Case 6
            $sMsg = "Invalid password."
        Case Else 
            $sMsg = "Error accessing remote share."
    EndSwitch
    $iMsgBoxAnswer = MsgBox($MB_YESNO + $MB_ICONERROR, "SHARE ACCESS ERROR" , $sMsg & @CRLF & @CRLF & "Would you like to try to connect again?")
    Select
        Case $iMsgBoxAnswer = $IDYES
        Case $iMsgBoxAnswer = $IDNO
            Exit 
    EndSelect
    
    $aUser[1] = ""
WEnd

If Not FileCopy($sLocalPath, $sSharePath, $FC_OVERWRITE) Then Exit MsgBox($MB_ICONERROR, "ERROR!", "Error copying file.")

DriveMapDel($sMappedDrive)

 

Adam

 

Posted

Try without the mapping and using UNC like:

Keep in mind that you may not have permissions to do it - have you tried to do it manually?

FileCopy ( "C:\Users\user\Desktop\test.zip", "\\xxxxxxxx\xxx\xxxxxx\Users\user\Desktop",0)

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...