how to run an ftp script silently?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
iricivek
Posts: 2
Joined: 23 Sep 2021, 10:17

how to run an ftp script silently?

Post by iricivek » 23 Sep 2021, 10:28

Hi all, so I am trying to run a batch file to upload file via ftp using an ftp utility called cmdftp. It is almost the same as window's native ftp. I know how to run the batch file silently, but the batch file calls a script that I don't know how to hide (so whenever this file runs, the command line windows will pop up until it is finished)

the batch file is (you can actually replace cmdftp with ftp)

Code: Select all

cmdftp -s:ftpscript.txt -d:"Log.txt"
the script is

Code: Select all

open ftp.drivehq.com
USERNAME
xxxxxxxxx
cd test
delete orders.xml.bak
rename orders.xml orders.xml.bak
put c:\test\orders.xml
quit
I can add @echo off to the bat file but not the script itself. Any help is greatly appreciated!
Last edited by BoBo on 12 Feb 2022, 17:31, edited 1 time in total.
Reason: Moved to 'Ask for Help'.

garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: how to run an ftp script silently?

Post by garry » 25 Sep 2021, 11:28

here just a basic example with DOS run hidden

Code: Select all

F1=%a_desktop%\test33.txt
fileappend,Line1`r`nLine`r`n,%f1%,utf-8
msgbox, 262180,TEST , Now you see the file test33.txt at Desktop`nThis will be deleted if use YES-Button`r`nWant you delete this testfile '%f1% ? 
ifmsgbox,NO
  exitapp
e4x=
(Ltrim join&
@echo off
echo date=
date /t
echo time=
time /t
del "%f1%"
)
;runwait, %comspec% /k %e4x%,,,pid2       ;- see what happens in DOS
runwait, %comspec% /c %e4x%,,hide,pid2    ;- see nothing but the file %a_desktop%\test33.txt should be deleted 
Exitapp

iricivek
Posts: 2
Joined: 23 Sep 2021, 10:17

Re: how to run an ftp script silently?

Post by iricivek » 25 Sep 2021, 12:26

garry wrote: here just a basic example with DOS run hidden

Code: Select all

F1=%a_desktop%\test33.txt
fileappend,Line1`r`nLine`r`n,%f1%,utf-8
msgbox, 262180,TEST , Now you see the file test33.txt at Desktop`nThis will be deleted if use YES-Button`r`nWant you delete this testfile '%f1% ? 
ifmsgbox,NO
  exitapp
e4x=
(Ltrim join&
@echo off
echo date=
date /t
echo time=
time /t
del "%f1%"
)
;runwait, %comspec% /k %e4x%,,,pid2       ;- see what happens in DOS
runwait, %comspec% /c %e4x%,,hide,pid2    ;- see nothing but the file %a_desktop%\test33.txt should be deleted 
Exitapp
Thank you much! I'm trying to study your script. what does the ltrim and echo date and echo time do in the e4x argument? thank you

garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: how to run an ftp script silently?

Post by garry » 25 Sep 2021, 12:57

if you run DOS not hidden then see date and time
e4x is variable with chained commands , Ltrim join& > add & at end of line , example : ver&dir

https://www.etcwiki.org/wiki/Windows_Command_Line:_Beginners_Guide

Chaining Commands
When there are multiple commands you want to run at one time, Chaining commands in Windows Command Line comes in handy.
To chain a command, we have two tools.

& - Complete one command then another directly after Usage: command & command2 Example: dir & ver
Explanation: This will list all files in current directory and then the version of Windows Command Line

&& - Complete one command, then another if the first was successful Usage: <command1> && <command2> Example: copy c:\importantdata.txt c:\backup\ && ren backupdata.txt
Explanation: This will copy the file importantdata.txt to c:\backup\, THEN if successful, it will rename the file to backupdata.txt

garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: how to run an ftp script silently?

Post by garry » 25 Sep 2021, 13:26

I have no answer for FTP , here only DOS example with AHK

maybe can also ask in forum 'Ask For Help' :
viewforum.php?f=76

Code: Select all

;=========== EXAMPLE-1 ===============================
;- run as admin "powercfg /L |clip"
;- search for german word 'Ausbalanciert'
;- if found then write  > found OK or otherwise NOT OK
;- run "powercfg /? |clip"  > powercfg help
;- run textfile > %a_desktop%\%a_now%_powercfg_test.txt
;-
#SingleInstance, Force
;----------------------------------------
F1=%a_desktop%\%a_now%_powercfg_test.txt
searchfor=Ausbalanciert   ;- german word
;---------------------------------------
If !A_IsAdmin
	Run *RunAs "%A_AhkPath%" "%A_ScriptFullPath%"
Process, Priority, , H
;RunWait, %comspec% /c "powercfg -energy"            ;- writes to 'energy-report.html'
RunWait, %comspec% /c "powercfg /L |clip",,hide"     ;- list (without admin)
cx .= "============ powercfg LIST ========================`r`n" . clipboard      ;- contains the german word > "Ausbalanciert"
if cx contains %searchfor%
  cx .= "`r`ncontains " . searchfor . " so it's > OK`r`n"
else
  cx .= "`r`nNOT contains " . searchfor . " so it's > NOT OK`r`n"
RunWait, %comspec% /c "powercfg /? |clip",,hide      ;- help
cx .="`r`n============ powercfg HELP ========================`r`n" . clipboard
fileappend,%cx%,%f1%,utf-8
try
  run,%f1%
clipboard=
cx=
return
;=====================================================

Code: Select all

;========= Example-2 =================================
/*
- run DOS with defined size/position and color
- chained command date and time and add other commands then close DOS after 5 seconds
-
*/
;----------------------------------------------------- 
#warn
#NoEnv                       ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input               ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
wa:=a_screenwidth,ha:=a_screenheight,W :=(wa*50)/100,H :=(ha*92)/100
e4x=
(Ltrim join&
@echo off
echo date=
date /t
echo time=
time /t
)
title2=DOS_TEST
run, %comspec% /T:0A /k "title %title2%&mode con lines=4000 cols=120&%e4x%,,,pid2
WinWait, ahk_pid %pid2%
WinMove, ahk_pid %pid2%, ,1,1,%w%,%h%       ;- move DOS window to the defined position
;sleep,3000
WinWaitactive, ahk_pid %pid2%
;SendInput {text}ver`n
controlsend,ahk_parent,{text}ver`n,ahk_pid %pid2%
sleep,1000
controlsend,ahk_parent,{text}REM url=http://127.0.0.1:8889`n,ahk_pid %pid2%
sleep,100
controlsend,ahk_parent,{text}REM -- DOS quit's in 5 seconds`n,ahk_pid %pid2%
sleep,5000
controlsend,ahk_parent,{text}exit`n,ahk_pid %pid2%
return
;===================================================

JuneAmara
Posts: 1
Joined: 03 Feb 2022, 05:00

Re: how to run an ftp script silently?

Post by JuneAmara » 03 Feb 2022, 05:36

Code: Select all

@echo off
echo date=
date /t
echo time=
time /t
del "%f1%"  run errors

Post Reply

Return to “Ask for Help (v1)”