Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

FTP File Transfer Script


  • Please log in to reply
12 replies to this topic
jeanieb
  • Members
  • 3 posts
  • Last active: Nov 20 2004 04:21 PM
  • Joined: 10 Oct 2004
Does anyone have a sample of a scrupt using the native windows FTP client to transfer a file from an FTP server to the local system?

The examle below does not work every time. I believe I need to use a TXT file for the FTP script part instead of typing it in. It appears either the cmd.exe window or the FTP connection does not really close and remains running or something. I have changed the IP address and login information for obvious reasons!

Home:

InputBox, JobNo, SmartSCRIPT Get 20 PHX Job, Enter Job No., ,250, 150
if ErrorLevel <> 0
Gosub, Finish
else
Gosub, Cont
Cont:
WinMinimize
Run, cmd
WinWait, C:\WINDOWS\system32\cmd.exe,
IfWinNotActive, C:\WINDOWS\system32\cmd.exe, , WinActivate, C:\WINDOWS\system32\cmd.exe,
WinWaitActive, C:\WINDOWS\system32\cmd.exe,
Send, cd{SPACE}\ascend{ENTER}md{SPACE}Voice{ENTER}cd{SPACE}Voice{ENTER}
Send, ftp{SPACE}000.000.000.000{ENTER}
Send, user{SPACE}user{SPACE}pwd{ENTER}
WinWait, C:\WINDOWS\system32\cmd.exe - ftp,
IfWinNotActive, C:\WINDOWS\system32\cmd.exe - ftp, , WinActivate, C:\WINDOWS\system32\cmd.exe - ftp,
WinWaitActive, C:\WINDOWS\system32\cmd.exe - ftp,
Send, cd{SPACE}/assigned/20{ENTER}prompt{ENTER}hash{ENTER}mget{SPACE}%JobNo%.*{ENTER}disconnect{ENTER}quit{ENTER}
WinWait, C:\WINDOWS\system32\cmd.exe,
IfWinNotActive, C:\WINDOWS\system32\cmd.exe, , WinActivate, C:\WINDOWS\system32\cmd.exe,
WinWaitActive, C:\WINDOWS\system32\cmd.exe,
Send, exit{ENTER}
WinWaitClose, C:\WINDOWS\system32\cmd.exe - ftp
WinWaitClose, C:\WINDOWS\system32\cmd.exe
Gosub, Home
Finish:
Exit

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
u're right...u need to use a text file with all the commands as the input script.

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


BoBo
  • Guests
  • Last active:
  • Joined: --
You can do the dynamic part of the FTP up-/download using the "-s:filename" argument of the FTP command.

InputBox, JobNo, SmartSCRIPT Get 20 PHX Job, Enter Job No., ,250, 150
if ErrorLevel <> 0
{
MsgBox, Error !
ExitApp
}
RunWait, %COMSPEC% /C cd ascend,,Hide
RunWait, %COMSPEC% /C md Voice,,Hide
RunWait, %COMSPEC% /C cd Voice,,Hide
FileAppend, user JohnDoe`npwd MyPassword`ncd /assigned/20`nprompt hash`nmget %JobNo%.*`ndisconnect`nquit`n, MyFTPDownload.txt

RunWait, %COMSPEC% /C ftp 000.000.000.000 -s:MyFTPDownload.txt,,Hide

FileDelete, MyFTPDownload.txt

MsgBox, Done.
ExitApp


As usual.
Untested braindump :roll:
Uncommented. :oops:
8)

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Thanks for sharing that. It might help until such time as AutoHotkey supports HTTP/FTP uploading, which might be a while.

jeanieb
  • Members
  • 3 posts
  • Last active: Nov 20 2004 04:21 PM
  • Joined: 10 Oct 2004
For some reason, I could not get this script to move to the C:\Ascend folder and consequently it would not create the voice folder.

Any ideas? It SHOULD work...

BoBo
  • Guests
  • Last active:
  • Joined: --
Maybe you can ignore the "cd ascend" route and use md to create the "Voice" directory this way:

Creates a directory.

MKDIR [drive]path
MD [drive]path

If Command Extensions are enabled MKDIR changes as follows:

MKDIR creates any intermediate directories in the path, if needed.
For example, assume \a does not exist then:

mkdir \a\b\c\d

is the same as:

mkdir \a
chdir \a
mkdir b
chdir b
mkdir c
chdir c
mkdir d

which is what you would have to type if extensions were disabled.


RunWait, %COMSPEC% /C md \ascend\Voice,,Hide

Additionaly you should use within the FTP file --> lcd (change the local directory) to swap to the local directory /ascend/Voice

lingoist
  • Members
  • 122 posts
  • Last active: Jan 28 2014 03:50 PM
  • Joined: 05 Oct 2004

Thanks for sharing that. It might help until such time as AutoHotkey supports HTTP/FTP uploading, which might be a while. (Chris wrote)


It would be really nice if there were FTP/HTTP upload/download engines!

lingoist
  • Members
  • 122 posts
  • Last active: Jan 28 2014 03:50 PM
  • Joined: 05 Oct 2004
Bobo,

What does "JobNo" mean?

Thanks,
Alfredo

BoBo
  • Guests
  • Last active:
  • Joined: --

...

InputBox, JobNo, SmartSCRIPT Get 20 PHX Job, Enter Job No., ,250, 150


:idea: Guess it's: Please enter "Job number"

lingoist
  • Members
  • 122 posts
  • Last active: Jan 28 2014 03:50 PM
  • Joined: 05 Oct 2004
I already knew it, but I was trying to guess what this number would mean. As fas as my windows is 98, do you think this script would work. I hasn't had any effect at all....

  • Guests
  • Last active:
  • Joined: --

You can do the dynamic part of the FTP up-/download using the "-s:filename" argument of the FTP command.

InputBox, JobNo, SmartSCRIPT Get 20 PHX Job, Enter Job No., ,250, 150
if ErrorLevel <> 0
{
MsgBox, Error !
ExitApp
}
RunWait, %COMSPEC% /C cd ascend,,Hide
RunWait, %COMSPEC% /C md Voice,,Hide
RunWait, %COMSPEC% /C cd Voice,,Hide
FileAppend, user JohnDoe`npwd MyPassword`ncd /assigned/20`nprompt hash`nmget %JobNo%.*`ndisconnect`nquit`n, MyFTPDownload.txt

RunWait, %COMSPEC% /C ftp 000.000.000.000 -s:MyFTPDownload.txt,,Hide

FileDelete, MyFTPDownload.txt

MsgBox, Done.
ExitApp


As usual.
Untested braindump :roll:
Uncommented. :oops:
8)



daonlyfreez
  • Members
  • 995 posts
  • Last active: Jan 23 2013 08:16 AM
  • Joined: 16 Mar 2005
I don't think AHK should have direct support for ftp uploading/http posting...

This is a security issue. If AHK get's native support for uploading files, this would open the way to creating trojans/spyware with AHK.

Ofcourse one can run the ftp command line utility, use a few dllcalls and bypass security too, but that is still different from native support, malign actions would be far easier to track with an antivirus/trojan scanner/firewall without support for upping in AHK...
Posted Image mirror 1mirror 2mirror 3ahk4.me • PM or Posted Image

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
It's true that FTP support might never get built-in, especially since someone could make a #include'able set of functions that call the OS's built in FTP functions.

Also, BoBo's method above is quite useful. It can be further improved via a continuation section. At the bottom of the FileAppend page, there's is a complete example of performing uploads and other tasks on an FTP server.