Sign in to follow this  
Followers 0
SlimShady

Remote Download (& Execute)

11 posts in this topic

#1 ·  Posted (edited)

When I read this topic I felt like this is very useful.

What this script does:

  • Download files from your personal ftp/webserver to your home PC

    If you have scripts you're working on at work/school and want to run 'em:

    - You upload the scripts to the webserver

    - You edit the settings.ini to tell which script to download and run automatically

  • Download files from anywhere to your PC at home
Features:
  • Any file you put in settings.ini will only download once.
  • A logfile is created
  • Any file you want to download & run will only download & run once.
  • By editing the ini file you can set n minutes to pause before checking for a new settings.ini.

    The settings.ini is downloaded infinite times and the script is run infinite times and pauses n minutes.

  • By setting "Run=No" you can tell the script to not do anything until it says "Run=Yes".
Settings.ini

[Settings]
Run=Yes
Refresh=1
Website=
DownloadFile=none
DownloadUrl=none
SaveDownloadAs=
  • Run: can be Yes/No. Do something/do nothing.
  • Refresh: number of minutes to pause before downloading the settings.ini
  • Website: has to be a location where your settings.ini is

    enter the full URL including a slash at the end

  • DownloadFile: Download & run a certain file from Website

    Required: If you want to disable this enter: none, else enter only a filename.

  • DownloadUrl: a file that you want to download to your PC at home

    Required: If you want to disable this enter: none, else enter the full URL.

  • SaveDownloadAs file name of the download DownloadUrl

    enter only a filename.

If something goes terribly wrong, tell me.

I don't expect it, I tested the script for an hour. It works like I wanted.

Besides, if you want to download & run a certain file, you can add the delete function after the run command.

Instructions:

- Edit the settings.ini and set Run=No

- Upload the settings.ini to a webserver or FTP server (manually)

- Run the script on the PC where you save all your scripts and files

- If you're at work/school, access the webserver or FTP server (manually) and download the settings.ini

- Edit the ini file to your likings and upload it again

If you have suggestions, ideas. Please post it here.

Thank you and have fun!

;--------- Declare variables
Global $Today, $Nextday, $Website, $Date

$Date = @MON & "/" & @MDay

$Folder = "C:\scripts\remote"
$Temp = $Folder & "\temp"
$Downloads = $Folder & "\Downloads"

DirCreate($Folder)
DirCreate($Temp)

$CheckINI = @ScriptDir & "\settings.ini"
$Logfile = $Folder & "\Logfile.txt"

$NextDay = @MDAY + 1

$Today = @MON & "/" & @MDAY
$NextDay = @MON & "/" & $NextDay

Do
   URLDownloadToFile($Website & "settings.ini", $CheckINI)
   $Run = IniRead($CheckINI, "Settings", "Run", "")

   If $Run = "Yes" Then

      $Website = IniRead($CheckINI, "Settings", "Website", "")
      $DownloadFile = IniRead($CheckINI, "Settings", "DownloadFile", "")
      
      If $DownloadFile <> "none" Then
         $Extension = StringRight($DownloadFile, 4)
         
         $ProgramPath = $Temp & "\" & $DownloadFile
         
         Select
            Case $Extension = ".htm" Or $Extension = "html"
               $Program = "explorer " & $ProgramPath
            Case $Extension = ".ini" Or $Extension = ".txt"
               $Program = "notepad " & $ProgramPath
            Case $Extension = ".au3"
               $Program = "C:\Progra~1\AutoIt\AutoIt3.exe " & $ProgramPath
            Case $Extension = ".vbs"
               $Program = "wscript " & $ProgramPath
         EndSelect
         
         If Not FileExists($ProgramPath) Then
            URLDownloadToFile($Website & $DownloadFile, $ProgramPath)
            If FileExists($ProgramPath) Then
               $CurTime = @HOUR & ":" & @MIN
               $OpenLogfile = FileOpen($Logfile, 1)
  FileWriteLine($OpenLogfile, $Date & " " & $CurTime & " -> File downloaded from: " & $Website & $DownloadFile)
               FileClose($OpenLogfile)
            EndIf

           $CurTime = @HOUR & ":" & @MIN
           Run($Program)
           $OpenLogfile = FileOpen($Logfile, 1)
           FileWriteLine($OpenLogfile, $Date & " " & $CurTime & " -> File started: " & $DownloadFile)
           FileClose($OpenLogfile)

         EndIf

      EndIf

      $DownloadUrl = IniRead($CheckINI, "Settings", "DownloadUrl", "")

      If $DownloadUrl <> "none" Then

         DirCreate($Downloads)
         $SaveDownloadAs = IniRead($CheckINI, "Settings", "SaveDownloadAs", "")

         If Not FileExists($Downloads & "\" & $SaveDownloadAs) Then
         URLDownloadToFile($DownloadUrl, $Downloads & "\" & $SaveDownloadAs)
         $CurTime = @HOUR & ":" & @MIN
         $OpenLogfile = FileOpen($Logfile, 1)
         FileWriteLine($OpenLogfile, $Date & " " & $CurTime & " -> File downloaded from: " & $DownloadUrl)
         FileClose($OpenLogfile)
         EndIf
      EndIf
   EndIf
   
   $Extension = ""
   $Refresh = IniRead("C:\scripts\settings.ini", "Settings", "Refresh", "")
   $Refresh = Number($Refresh)
   
   Sleep($Refresh * 60 * 1000)
Until $Today = $Nextday

Exit
Edited by SlimShady

Share this post


Link to post
Share on other sites



so, how would i log in to an FTP account with this so that the program can see the files?


-Brett

Share this post


Link to post
Share on other sites

Sorry, I forgot to add instructions. I will put them in the first post.

Share this post


Link to post
Share on other sites

OK, THIS IS HARD TO EXPLAIN, but i am going to make an attempt so that someone can help me.

What i want to do is when the script inputs a command, it will go to a function where it checks to see if there are any new files in an FTP i created for file transfer between my home computer and a remote computer. When it receives the command, i want it to go to

ftp://username:password@hostname/

and check to see if there are any new files. Or, if i could use a settings.ini file like in SlimShady's Script, that be even nicer. Then, i want the script to run it with the "yes" or "no" in slim's script.

SlimShady, could i use your script above to do all of this?

Thanks

Brett


-Brett

Share this post


Link to post
Share on other sites

I tested it but it doesn't work. AutoIt can only download from a (http) webserver.

BTW: there's a Select Case in my script where you can set the program paths for any filetype. You will have to change the path to AutoIt.

Share this post


Link to post
Share on other sites

Hmm? I have dled a txt file from ftp using urldltofile.

Share this post


Link to post
Share on other sites

Hmm? I have dled a txt file from ftp using urldltofile.

Ditto !

Share this post


Link to post
Share on other sites

Using ftp://username:password@hostname/ like Brett said?

It didn't work here.

I can't remember the link I used.... :D

Anyway...

Just remember if you're using UrlDownloadToFile with a ftp-link (which contains username password),

remember that there is a decompiler "out on the market" now...

So if you share your script with anyone, you should keep in mind that it's not so

hard for "them" to get their hands on your username and password..

Even if the script is compiled !

Just a little reminder..and warning !

Share this post


Link to post
Share on other sites

You could edit the ini file:

Website=ftp://user:pass@domain/

And it should work. If it doesn't, I can't help it.

So my script downloads for example: ftp://user:pass@domain/settings.ini

Share this post


Link to post
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
Sign in to follow this  
Followers 0