Jump to content

Simple Zip and FTP Upload Script


NobodyWannabe
 Share

Recommended Posts

#include <FTPEx.au3>


;Online Backup
$source = '"C:BackupsDirectory*"'          ;Source directory to backup
$7Zfile = "C:BackupsDirectoryFileName.7z"  ;Backup file name
$pw     = "-p12345 -mhe"                      ;7-Zip Password (7z file will be password protected with 12345)

FileDelete($7Zfile)
sleep(500)

;Change "C:Apps" to where 7-Zip is installed
Run("C:Apps7-Zip7zG a " & $7Zfile & "  " & $pw & " " & $source)



;Upload Backup to Server
ProcessWaitClose("7zG.exe")

$server   = 'ftp.server.com' ;FTP Server
$username = 'username'       ;FTP Username
$pass     = 'password'       ;FTP Password

$Open = _FTP_Open('MyFTP Control')
$Conn = _FTPConnect($Open, $server, $username, $pass,0,1,0x08000000)

 ;Hard drive source file and server directory (change to suit)
$Ftpp = _FtpPutFile($Conn,"C:BackupsDirectoryFileName.7z", '/FileName.7z' , 0x08000000)


Func _FTPConnect($l_InternetSession, $s_ServerName, $s_Username, $s_Password, $i_ServerPort = 0, $l_Service = 1, $l_Flags = 0, $l_Context = 0)

    Local $ai_InternetConnect = DllCall('wininet.dll', 'long', 'InternetConnect', 'long', $l_InternetSession, 'str', $s_ServerName, 'int', $i_ServerPort, 'str', $s_Username, 'str', $s_Password, 'long', $l_Service, 'long', $l_Flags, 'long', $l_Context)
    If @error OR $ai_InternetConnect[0] = 0 Then
        SetError(-1)
        Return 0
    EndIf

    Return $ai_InternetConnect[0]

EndFunc
Func _FtpPutFile($l_FTPSession, $s_LocalFile, $s_RemoteFile, $l_Flags = 0, $l_Context = 0)

    Local $ai_FTPPutFile = DllCall('wininet.dll', 'int', 'FtpPutFile', 'long', $l_FTPSession, 'str', $s_LocalFile, 'str', $s_RemoteFile, 'long', $l_Flags, 'long', $l_Context)
    If @error OR $ai_FTPPutFile[0] = 0 Then
        SetError(-1)
        Return 0
    EndIf

    Return $ai_FTPPutFile[0]

EndFunc

Edited by Melba23
Added code tags
Link to comment
Share on other sites

When posting code please use a code tag, it makes it much easier to glance at a sample like yours without having to copy it in to SciTE. To do this, please use BRACKETAutoitCLOSEBRACKET before the code, and BRACKET/AutoitCLOSEBRACKET after the code. And of course by BRACKET I mean [ and ].

Ian

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
Link to comment
Share on other sites

  • 4 weeks later...

This is almost exactly what I need and I've tested it out and got as far as the zip file being created.

Since I'm getting stuck at the start of the FTP part, I assume I need to modify the items that appear in red in the following lines, but I'm not sure what they mean. Could you please comment on what these items are? It seems to me that some of these are defined already so clearly I have a lot to learn!

$Open = _FTP_Open('MyFTP Control') ; MyFTP Control = ?????

Local $ai_InternetConnect = DllCall('wininet.dll', 'long', 'InternetConnect', 'long', $l_InternetSession, 'str', $s_ServerName, 'int', $i_ServerPort, 'str', $s_Username, 'str', $s_Password, 'long', $l_Service, 'long', $l_Flags, 'long', $l_Context)
; need to modify these for my connection/server, or already defined?

Local $ai_FTPPutFile = DllCall('wininet.dll', 'int', 'FtpPutFile', 'long', $l_FTPSession, 'str', $s_LocalFile, 'str', $s_RemoteFile, 'long', $l_Flags, 'long', $l_Context)
; need to modify these for my connection/server, or already defined?

Also, I'd like to be able to zip the currently selected file/files/folder rather than a pre-defined file (i.e, I'd like to put this into the right-click menu, as my use is not as a backup but as a distribution to different FTP folders, hence the need for at least one manual step).

Any suggestions as to where/how to modify your code to do this?

thanks for any and all help!

Link to comment
Share on other sites

sorry, forget the first part - figured it out and tweaked things bit, have managed to make the FTP connection and upload was successful.

Now I'm just wondering about using it on single or multiple selected file(s)/folder(s) for individual uploads to FTP.

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

  • Recently Browsing   0 members

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