Automating WinSCP file transfer in Python using using pywinauto

Question:

I am trying to automate a file transfer process in WinSCP using Python and pywinauto. I am currently sending keyboard keys of Ctrl+ to open a directory and search a path, but when I run my program, it will not open the open directory window. Please help!

kb.send_keys("^0")

app1 = Application().connect(title=u'Open directory')
win1 = app1.TOpenDirectoryDialog

src_folder = "/data/cog/deployments"
win1[u'Edit'].type_keys(src_folder)
win1.OK.click()

This is the error code I am getting:

Traceback (most recent call last):
  File "C:UsersRARPycharmProjectspythonAutomationprojmain.py", line 49, in <module>
    app1 = Application().connect(title=u'Open directory')
  File "C:UsersRARPycharmProjectspythonAutomationprojvenvlibsite-packagespywinautoapplication.py", line 997, in connect
    self.process = findwindows.find_element(**kwargs).process_id
  File "C:UsersRARPycharmProjectspythonAutomationprojvenvlibsite-packagespywinautofindwindows.py", line 87, in find_element
    raise ElementNotFoundError(kwargs)
pywinauto.findwindows.ElementNotFoundError: {'title': 'Open directory', 'backend': 'win32', 'visible_only': False}
Asked By: Rae

||

Answers:

Do not try to implement file transfer by automating WinSCP GUI!

Use WinSCP scripting. Start at:
https://winscp.net/eng/docs/guide_automation

WinSCP GUI can even generate script template for you:
https://winscp.net/eng/docs/guide_automation#generating


Or use native Python file transfer libraries. ftplib for FTP. Or Paramiko for SFTP.

Answered By: Martin Prikryl
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.