check the ftp-server - CMD-commands

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Albireo
Posts: 1777
Joined: 16 Oct 2013, 13:53

check the ftp-server - CMD-commands

15 May 2024, 18:00

Hi!
My desire is to check if the ftp server is ok.
The strategy is to check if there are files in a directory.
and want to accomplish this with the following commands .:
  • 1) Run the Win CMD
  • 2) ftp ???.???.???.??? (the IP- to the ftp-server
  • 3) username
  • 4) password
  • 5) ls (List the files on the ftp server)
  • 6) bye (Shut down the communication with the ftp server)
  • 7) exit (Close the CMD window)
Didn't think to create an ftp account to test.
Wanted to understand the possibilities, by just running some common local commands,
How to send multiple commands to CMD - on the best way?
(Should probably wait for a response from the ftp server after each input.
Analyze the answers - provide information if e.g. the message "access denied" is displayed.)

In the ahk documentation I found the following example .:

Code: Select all

RunWait A_ComSpec " /c dir C:\ >>C:\DirTest.txt", , "Min"
Run "C:\DirTest.txt"
Run "properties C:\DirTest.txt"
Persistent
It works if the script is run as administrator - I got a result.
Moved the result file (dirTest.txt) from C:\ to another better temp-location.
(and now I don't need to run as administrator :D )
Each CMD-command produces a response
The program is done!
User avatar
Noitalommi_2
Posts: 287
Joined: 16 Aug 2023, 10:58

Re: check the ftp-server - CMD-commands

16 May 2024, 10:22

Hi.
Albireo wrote:
15 May 2024, 18:00
...
My desire is to check if the ftp server is ok.
...
I don't know, maybe you're already using this but you could use ping to check whether the server is ok. If the server sends a response, then the server should be ok.

Code: Select all

#Requires AutoHotkey 2.0
#SingleInstance


MsgBox Ping("www.google.com")
MsgBox Ping("ftp.gnu.org")

Ping(Url) {

	; https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/ping
	objShell := ComObject("WScript.Shell")
	objExec := objShell.Exec("Ping " Url)
	return Url "`n`n" objExec.StdOut.ReadAll()
}
Albireo
Posts: 1777
Joined: 16 Oct 2013, 13:53

Re: check the ftp-server - CMD-commands

16 May 2024, 15:37

Thank you!

I'm not sure "ping" is enough for me.
By logging into the FTP server, and checking something
(it can be LS or check that a file exists or ...)
some other things are checked such as firewall etc.
Not just that the FTP server exists.

Last week my FTP user stopped working. Could not log in as that user.
But before I understood the problem, I had checked a lot of other things.

Now I thought of writing a small script to quickly check that everything works.
Have started with a strategy but not getting it to work (see following post Send the output of program execution to a variable)
User avatar
Noitalommi_2
Posts: 287
Joined: 16 Aug 2023, 10:58

Re: check the ftp-server - CMD-commands

16 May 2024, 20:10

Could try something like this.

Code: Select all

#Requires AutoHotkey 2.0
#SingleInstance


OutputVar :=  Mtee("/?") ;  lists options
MsgBox OutputVar


Mtee(Options) {
	; script & mtee.exe must be in the same folder
	CommandLine := A_WorkingDir . "\mtee.exe " . Options
	objShell := ComObject("WScript.Shell")
	objExec := objShell.Exec(CommandLine)
	return objExec.StdOut.ReadAll()
}
Albireo
Posts: 1777
Joined: 16 Oct 2013, 13:53

Re: check the ftp-server - CMD-commands

18 May 2024, 05:21

Thank you!
but...
The problem is more compliucated and this. (maybe my desire is insoluble)
When the program itself, is produce the result, there is no problem. In your example the result is produced by Mtee.
the same is for this script. (No problem)

Code: Select all

RunWait A_ComSpec " /c dir C:\  | clip ",, "Min"
MsgBox A_Clipboard
but the command ftp ??.??.??.?? produces nothing.
The result/answer is coming from the ftp server, and I want to analyze that message.
  • case 1 - No response within ?? seconds = trouble
  • case 2 - Wrong answer = problem

This program handles my desire in a way - but I don't want to create the temporary file, to be able to parse the output from the server.

Code: Select all

#Requires AutoHotkey 2.0
#SingleInstance

A_Clipboard := ''
Mtee := '.\mtee.exe'
outFile := '.\mteeTemp.txt'
ipAdr := '??.??.??.??'

runArgs := " /c ftp " ipAdr " | " Mtee " " outFile
Run A_ComSpec runArgs

Sleep 1000	; Give time to produce the file
MyText := FileRead(outFile)
MsgBox "Done! `n" MyText
The response sent by the FTP server may look like the following.
Connected to ??.??.??.
220-Microsoft FTP Service
220 Loopia
200 OPTS UTF8 command successful - UTF8 encoding now ON.
User (??.??.??.??:(none)):



Once the response from the ftp-server is parsed and approved, the username should be sent to the same CMD window (and so on)

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Google [Bot], pgeugene, songdg and 17 guests