VBA Scripts to Control Win SCP actions
I have started playing with VBA in order to automate some of the workload within my team. We use WinSCP to house our files and therefore I would ultimately like to build a script that downloads a daily file from the FTP to a local directory and has them ready for working at 6am every morning.
I have designed a script based on 'SendKeys' that logs the user onto the WinSCP GUI, however downloading a file from the FTP directory and relocating to a local directory is becoming quite a challenge.
I'm not sure if I'm approaching this in the incorrect way... or need to look at an alternative.
I have seen that Win WCP supports 'command lines' however I don't really have a clue what this means, I think I might need to design a 'session' and interact via the command lines. However I don't know where to start.
My code so far is as below:
[Code]
Sub Login_SCP_FTP()
'Open WinSCP and Determine it as a object
Dim WinSCP_Start_App As Long
WinSCP_Start_App = shell("C:\Program Files\WinSCP\WinSCP.exe <IP_ADDRESS>", vbNormalFocus) 'location of the WinSCP exe and also the IP/Host Name
Dim WinSCP_Username As String
WinSCP_Username = "<unsername>" 'Username
Dim WinSCP_Password As String
WinSCP_Password = "<PASSWORD>" 'Password
'Variables the indicate the Application Window Names for each stage
Dim WinSCP_Login_Step1 As String
WinSCP_Login_Step1 = "Username - <IP_ADDRESS>" 'Login app step1 for username entry
Dim WinSCP_Login_Step2 As String
WinSCP_Login_Step2 = "Password - <IP_ADDRESS>" 'Login app step1 for password entry
Dim WinSCP_Active_App As String
WinSCP_Active_App = "<IP_ADDRESS> - WinSCP" 'Application window name once login is sucessful
Application.Wait (Now + TimeValue("00:00:09"))
AppActivate WinSCP_Login_Step1, False
SendKeys WinSCP_Username 'Server Username
SendKeys "{TAB}~"
Application.Wait (Now + TimeValue("00:00:02"))
AppActivate WinSCP_Login_Step2, False
SendKeys WinSCP_Password 'Server Password
SendKeys "{TAB}{TAB}~"
Application.Wait (Now + TimeValue("00:00:10"))
AppActivate WinSCP_Active_App, False
SendKeys "%"
'Further script required to locate file and copy from SCP and move to local drive
End Sub
[Code/]
I have designed a script based on 'SendKeys' that logs the user onto the WinSCP GUI, however downloading a file from the FTP directory and relocating to a local directory is becoming quite a challenge.
I'm not sure if I'm approaching this in the incorrect way... or need to look at an alternative.
I have seen that Win WCP supports 'command lines' however I don't really have a clue what this means, I think I might need to design a 'session' and interact via the command lines. However I don't know where to start.
My code so far is as below:
[Code]
Sub Login_SCP_FTP()
'Open WinSCP and Determine it as a object
Dim WinSCP_Start_App As Long
WinSCP_Start_App = shell("C:\Program Files\WinSCP\WinSCP.exe <IP_ADDRESS>", vbNormalFocus) 'location of the WinSCP exe and also the IP/Host Name
Dim WinSCP_Username As String
WinSCP_Username = "<unsername>" 'Username
Dim WinSCP_Password As String
WinSCP_Password = "<PASSWORD>" 'Password
'Variables the indicate the Application Window Names for each stage
Dim WinSCP_Login_Step1 As String
WinSCP_Login_Step1 = "Username - <IP_ADDRESS>" 'Login app step1 for username entry
Dim WinSCP_Login_Step2 As String
WinSCP_Login_Step2 = "Password - <IP_ADDRESS>" 'Login app step1 for password entry
Dim WinSCP_Active_App As String
WinSCP_Active_App = "<IP_ADDRESS> - WinSCP" 'Application window name once login is sucessful
Application.Wait (Now + TimeValue("00:00:09"))
AppActivate WinSCP_Login_Step1, False
SendKeys WinSCP_Username 'Server Username
SendKeys "{TAB}~"
Application.Wait (Now + TimeValue("00:00:02"))
AppActivate WinSCP_Login_Step2, False
SendKeys WinSCP_Password 'Server Password
SendKeys "{TAB}{TAB}~"
Application.Wait (Now + TimeValue("00:00:10"))
AppActivate WinSCP_Active_App, False
SendKeys "%"
'Further script required to locate file and copy from SCP and move to local drive
End Sub
[Code/]