Sign in to follow this  
Followers 0
dbs179

WinSCP StdInWrite and StdOutRead

3 posts in this topic

Hi all,

I have a file I need to pull from an FTP site.  For one reason or another, I can't get this FTP site to work with Internet Explorer or with Windows Explorer and I have no control over the FTP site.  I've also not been able to use the built in FTP functions in AutoIT.  So I have resorted to using WinSCP.  I have a basic script set up to open cmd.exe, change dir to the correct winscp dir and then do all of the connections.  The problem is I want to be able to read the output of the window to ensure that the connections are established without using sleeps as I am now and want to be able to check the file download progress as the file is very large.  I've read the help on StdInWrite and StdOutRead, but haven't had much luck putting it all together for what I need.  Any help would be greatly appreciated.

Thanks,

Dave

Local $iPID = Run("CMD.exe")
WinWait ("C:\WINDOWS\system32\CMD.exe")
ControlSend("C:\WINDOWS\system32\CMD.exe", "", "", "CD C:\WinSCP Temp\" & @CR)
Sleep(500)
ControlSend("C:\WINDOWS\system32\CMD.exe", "", "", "WinSCP.com" & @CR)
WinWait ("WinSCP")
ControlSend("WinSCP", "", "", "open ftp://www.testftp.com:2121" & @CR)
Sleep(500)
ControlSend("WinSCP", "", "", "username" & @CR)
Sleep(500)
ControlSend("WinSCP", "", "", "Password" & @CR)
WinWait("www.testftp.com:2121 - WinSCP")
ControlSend("www.testftp.com:2121 - WinSCP", "", "", "Get *.iso " & @ScriptDir & "\" & @CR)

Share this post


Link to post
Share on other sites



Update, so I got to the point where I can go through the entire process and start the download, but I still am not sure how to check before sending the next StdInWrite and how to check the file process.  The output from STDoutRead and a new example of my script are below.  Thanks in advance for any help.

Dave

Debug:Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\WINDOWS\SysWOW64>cd C:\Temp\

C:\Temp>WinSCP.com
winscp> open ftp://www.testftp.com:2121
Prompting for credentials...
Username: username
Connecting to www.testftp.com:2121 ...
Connected with www.testftp.com:2121. Waiting for welcome message...
Password: Password
Connected
Starting the session...
Reading remote directory...
Session started.
Active session: [1] www.testftp.com
winscp> Get *.iso C:\Users\CurrentUser\Desktop\winscp553\
#include <Constants.au3>
$pid = Run("C:\WINDOWS\system32\CMD.exe",@SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
StdinWrite($pid,"cd ")
StdinWrite($pid,"C:\Temp\")
StdinWrite($pid,@CRLF)
StdinWrite($pid,"WinSCP.com")
StdinWrite($pid,@CRLF)
StdinWrite($pid,"open ftp://www.test-FTP.com:2121")
StdinWrite($pid,@CRLF)
StdinWrite($pid,"USERNAME")
StdinWrite($pid,@CRLF)
StdinWrite($pid,"PASSWORD")
StdinWrite($pid,@CRLF)
StdinWrite($pid,"Get *.iso " & @ScriptDir & "\" & @CR)
StdinWrite($pid,@CRLF)
Local $data
Sleep(2000)
$data &= StdoutRead($pid)

Share this post


Link to post
Share on other sites

Hi Dave,

Might I make a suggestion.  Look into building a "script" .txt file for WinSCP to use then the RunWait() command to launch WinSCP pointing to the script file.  The script will house your connection information and all 'get filename.iso' details.

I use FileWriteLine to create the WinSCP commands, line by line including 'get' commands for each file needed, then RunWait to execute WinSCP.com /script=yourscriptfile.txt.  Someone else may be able to assist with a progress meter, but I use a GUI that just gives a simple 'Downloading...'.

I hope that helps.

- Mike

Share this post


Link to post
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
Sign in to follow this  
Followers 0