Help with putting Variables into jNizM's FTPUpload script Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AgentZero
Posts: 17
Joined: 14 Nov 2021, 14:20

Help with putting Variables into jNizM's FTPUpload script

Post by AgentZero » 20 Mar 2023, 15:38

Had a look at jNizM's and it's been really useful. What I'm trying to do though is make the source filename and destination filename a variable.

Code: Select all


FTPUpload(srv, usr, pwd, lfile, rfile)
{
    static a := "AHK-FTP-UL"
    if !(m := DllCall("LoadLibrary", "str", "wininet.dll", "ptr")) || !(h := DllCall("wininet\InternetOpen", "ptr", &a, "uint", 1, "ptr", 0, "ptr", 0, "uint", 0, "ptr"))
        return 0
    if (f := DllCall("wininet\InternetConnect", "ptr", h, "ptr", &srv, "ushort", 21, "ptr", &usr, "ptr", &pwd, "uint", 1, "uint", 0x08000000, "uptr", 0, "ptr")) {
        if !(DllCall("wininet\FtpPutFile", "ptr", f, "ptr", &lfile, "ptr", &rfile, "uint", 0, "uptr", 0))
            return 0, DllCall("wininet\InternetCloseHandle", "ptr", h) && DllCall("FreeLibrary", "ptr", m)
        DllCall("wininet\InternetCloseHandle", "ptr", f)
    }
    DllCall("wininet\InternetCloseHandle", "ptr", h) && DllCall("FreeLibrary", "ptr", m)
    return 1
}

FileAppend, Hello, C:\Users\Myuser\PathToMyFile\%Variable2%.txt

FTPUpload("MyServer", "MyFTPUsername", "MyFTPPassword", "C:\Users\Myuser\PathToMyFile\%Variable2%.txt", "Test File.txt")
Variable 1 and 2 are grabbed from another part of the script. The FIleAppend part works all okay and it makes the file so I know the variable is there. And if I change the FTP part from %Variable2% to the actual content of the variable itself, it uploads.

Anyone able to point me in the direction of whatever I'm doing wrong?

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Help with putting Variables into jNizM's FTPUpload script  Topic is solved

Post by mikeyww » 20 Mar 2023, 16:37

Always use :arrow: expressions in functions.

From

"C:\Users\Myuser\PathToMyFile\%Variable2%.txt"

to

"C:\Users\Myuser\PathToMyFile\" Variable2 ".txt"

AgentZero
Posts: 17
Joined: 14 Nov 2021, 14:20

Re: Help with putting Variables into jNizM's FTPUpload script

Post by AgentZero » 20 Mar 2023, 17:25

mikeyww wrote:
20 Mar 2023, 16:37
Always use :arrow: expressions in functions.

From

"C:\Users\Myuser\PathToMyFile\%Variable2%.txt"

to

"C:\Users\Myuser\PathToMyFile\" Variable2 ".txt"
Thanks Mikey. This seems to have done the trick. Any reason why an expression is compulsory here but for the fileappend part?

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Help with putting Variables into jNizM's FTPUpload script

Post by mikeyww » 20 Mar 2023, 18:56

Yes. In AHK v1, commands use literal strings by default-- not expressions-- but functions always use expressions. Commands can force expressions when a parameter begins with % followed by a space.

When a command parameter is always a number, it can also accommodate an expression without %.

That's the answer. It's just how the syntax works.

Post Reply

Return to “Ask for Help (v1)”