Jump to content

Very Basic Help needed with ftp via command line and delays


Recommended Posts

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);
Send("USERNAME{ENTER}");
Sleep(3000);
Send("PASSWORD{ENTER}");
Sleep(3000);
Send("cd directory/structure/{ENTER}");
Send("prompt{ENTER}");
Send("mget images/{ENTER}");
Send("bye{ENTER}");
Sleep(10000);
Send("move /Y *.jpg C:\WHERE\its\downloaded\to{ENTER}");
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

Link to comment
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 :)

Link to comment
Share on other sites

  • 3 weeks later...

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
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...