Jump to content

Simple FTP Uploader


nf67
 Share

Recommended Posts

Simple uploader that uploads the file of which you have the path on your clipboard to an FTP server of choice when Ctrl + Y is pressed. Also has context menu support. For details, please see the screenshot below:

Posted Image

__________________________________________________________

Posted Image

__________________________________________________________

Source preview:

#include <FTPEx.au3>
#include <File.au3>
#include <Misc.au3>
#Include <String.au3>
#NoTrayIcon

If _Singleton("FTuP",1) = 0 Then
    Msgbox(0,"FTuP Error:","FTuP is already running!")
    Exit
EndIf

Opt("TrayMenuMode",1)
$HelpItem = TrayCreateItem("Help")
TrayCreateItem("")
$ExitItem = TrayCreateItem("Exit")
TraySetState()

$FileDrive = ""
$FileDir = ""
$FileName = ""
$FileExt = ""

HotKeySet("^y","Upload")

While 1
    $msg = TrayGetMsg()
    Select
    Case $msg = 0
    ContinueLoop
    Case $msg = $HelpItem
    Msgbox(0,"FTuP - CQE:","Press Ctrl+Y to upload the file of which the path is on the clipboard." &@CRLF& "After the beep, you can use Ctrl+V to paste the link." &@CRLF&@CRLF& _
                    "CONFIGURATION:" &@CRLF&@CRLF& _
                    "FTP details are in FTP.conf or encrypted in FTPsecure.conf, sorted by line:" &@CRLF& "1 = FTP Server" &@CRLF& "2 = FTP Account" &@CRLF& "3 = FTP Password" &@CRLF& _
                    "4 = Directory to put the file in, include first and last slash!" &@CRLF& "5 = URL to the folder where the file is placed, include last slash!" &@CRLF&@CRLF& _
                    "If you have both FTP.conf and FTPsecure.conf, then FTPsecure.conf will be used." &@CRLF&@CRLF& _
                    "Also, the file FTuP.size needs to be on the server in the directory where the files are uploaded (see 4 in the list above)." & _
                    " FTuP.size should contain the file size limit in megabytes (MB)." &@CRLF&@CRLF&@CRLF& _
                    "OPTIONAL:" &@CRLF&@CRLF& _
                    "FTuP Encrypt can turn your regular FTP.conf into an encrypted version." &@CRLF& _
                    "To enable right click file uploads, run FTuP RightClick.")
    Case $msg = $ExitItem
    ExitLoop
    EndSelect
WEnd

Func Upload()
    $FilePath = ClipGet()
    If FileExists($FilePath) = 0 Then
        MsgBox(0,"FTuP Error:","The file you want to upload couldn't be found. No FTP connection was made.")
    Else
        If FileExists(@ScriptDir & "\FTPsecure.conf") = 0 Then
            If FileExists(@ScriptDir & "\FTP.conf") = 0 Then
                MsgBox(0,"FTuP Error:","No config file could be found.")
                $NoConfigs = 1
            Else
                $FTPSecure = 0
                $FTPServer = FileReadLine(@ScriptDir & "\FTP.conf",1)
                $FTPAccount = FileReadLine(@ScriptDir & "\FTP.conf",2)
                $FTPPassword = FileReadLine(@ScriptDir & "\FTP.conf",3)
                $FTPDir = FileReadLine(@ScriptDir & "\FTP.conf",4)
                $SiteClip = FileReadLine(@ScriptDir & "\FTP.conf",5)
                $NoConfigs = 0
            EndIf
        Else
            $FTPSecure = 1
            $FTPServer = _StringEncrypt(0,FileReadLine(@ScriptDir & "\FTPsecure.conf",1),"F3T8u8P7")
            $FTPAccount = _StringEncrypt(0,FileReadLine(@ScriptDir & "\FTPsecure.conf",2),"F3T8u8P7")
            $FTPPassword = _StringEncrypt(0,FileReadLine(@ScriptDir & "\FTPsecure.conf",3),"F3T8u8P7")
            $FTPDir = _StringEncrypt(0,FileReadLine(@ScriptDir & "\FTPsecure.conf",4),"F3T8u8P7")
            $SiteClip = _StringEncrypt(0,FileReadLine(@ScriptDir & "\FTPsecure.conf",5),"F3T8u8P7")
            $NoConfigs = 0
        EndIf

        If $NoConfigs = 0 Then
            $FtpOpen = _FTP_Open("ImageFTP")
            $FtpConnect = _Ftp_Connect($FtpOpen,$FTPServer,$FTPAccount,$FTPPassword)
            If $FtpConnect = 0 Then
                If $FTPSecure = 0 Then
                    MsgBox(0,"FTuP Error:","Couldn't connect to the FTP server." &@CRLF& $FTPAccount & " + " & $FTPPassword & " on " & $FTPServer)
                Else
                    MsgBox(0,"FTuP Error:","Couldn't connect to the FTP server." &@CRLF& "Using encrypted FTP details.")
                EndIf
                _FTP_Close($FtpOpen)
            Else
                $FtpFileOpen = _FTP_FileOpen($FtpConnect,$FTPDir & "FTuP.size")
                If $FtpFileOpen = 0 Then
                    MsgBox(0,"FTuP Error:","FTuP.size couldn't be found, it should be on the server in the directory where the files are uploaded" & _
                    " (4th line of the configuration file). It should contain the file size limit in megabytes (MB).")
                    _FTP_Close($FtpOpen)
                Else
                    $FileSize = Round((FileGetSize($FilePath)/1048576),2)
                    $MaxSize = Number(BinaryToString(_FTP_FileRead($FtpFileOpen, 100)))
                    _FTP_FileClose($FtpFileOpen)
                    If $FileSize > $MaxSize Then
                        MsgBox(0,"FTuP Error:","Sorry, that file (" & $FileSize & " MB) exceeds the file size limit (" & $MaxSize & " MB) and will not be uploaded.")
                        _FTP_Close($FtpOpen)
                    Else
                        $PathSplit= _PathSplit($FilePath, $FileDrive, $FileDir, $FileName, $FileExt)
                        $File = Random(0,99,1) & $Filename & $FileExt
                        $FilePut = _FTP_FilePut($FtpConnect, $FilePath, $FTPDir & $File)
                        If $FilePut = 0 Then
                            MsgBox(0,"FTuP Error:", "Couldn't put the file on the server, despite a succesful connection.")
                            _FTP_Close($FtpOpen)
                        Else
                            _FTP_Close($FtpOpen)
                            ClipPut($SiteClip & $File)
                            Beep(500,100)
                        EndIf
                    EndIf
                EndIf
            EndIf
        EndIf
    EndIf
EndFunc

(please note that just the above piece of code does not include FTP details encryption and right click support)

DOWNLOAD SOURCE + 32-bit COMPILED + 64-bit COMPILED

Edited by nf67
Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...
  • 11 months later...

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...