Followers 0

# Very Basic Help needed with ftp via command line and delays

## 5 posts in this topic

Hey there, I am very new to scripting for AutoIt. I know a decent bit of PHP and C++, so my background isn't completely worthless.

I am going to post my code now. My goal is to download files from my server to my local computer so I can further process the files.

The problem right now is that the code does not wait for the terminal window to finish downloading the files. Any tips,

or example code would be much appreciated. I've browsed around the site and most of the code is way more complex than my

simple needs at the moment.

Run("cmd");
Sleep(2000);
Send("ftp{ENTER}");
WinWaitActive("C:\WINDOWS\system32\cmd.exe - ftp");
Send("open HOSTNAME{ENTER}");
Sleep(3000);
Sleep(3000);
Sleep(3000);
Send("cd directory/structure/{ENTER}");
Send("prompt{ENTER}");
Send("mget images/{ENTER}");
Send("bye{ENTER}");
Sleep(10000);
Sleep(10000);
Send("exit{ENTER}");
WinActivate("Window Title");
Sleep(3000);
MouseMove(499, 64);
Sleep(2000);
MouseClick("");

Any ideas on how to revamp this code to pause until my ftp finished transferring all of the files?

Any leads for tutorials for a noob would be greatly appreciated.

Thanks in advance for any help.

Best,

Doughty

##### Share on other sites

#2 ·  Posted (edited)

If you ask me, use WiseFTP Alot easier... atleast i do for my web servers

Edited by Steveiwonder

They call me MrRegExpMan

##### Share on other sites

Do a search for StdoutRead and StdinWrite; using them you can work out a command-response system (send a command and expect a certain response - the prompt - or an error message).

There should be several examples around.

In the actual form - you have no error control; whatever the server sends back (accept, deny connection ...,) you are waiting 3 seconds and send the user name anyway then regardless of the answer, you send the password....

DO a little bit of search and I'm sure you'll find something.

Good luck,

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

##### Share on other sites

I use the following for most all of my simple ftp processes. The downside is that there is no way to trap any error codes so I can't monitor for success or failure.

$ftpfile = "ftpfile.ftp" ;name of file that will be used for ftp responses$ftpfilename = FileOpen($ftpfile, 2) ;open the ftp file with write access, overwriting previous versions FileWriteLine($ftpfilename, "open 100.200.300.400")
FileWriteLine($ftpfilename, "username") FileWriteLine($ftpfilename, "password")
FileWriteLine($ftpfilename, "prompt") FileWriteLine($ftpfilename, "mget \\servername\sharename\filename*.* /foldername/*.*")
FileWriteLine($ftpfilename, "bye") FileClose($ftpfilename) ;close the ftp response file
RunWait(@ComSpec & " /c " & 'ftp -s:"' & $ftpfile & "", "", @SW_MINIMIZE) ;executes the ftp command using the contents of$ftpfile as responses to the prompts.
FileDelete(\$ftpfile) ;delete the ftp response file since it is no longer needed

##### Share on other sites

FTP UDF: http://www.autoitscript.com/forum/index.php?showtopic=78378