SFTP and PHP4
Another complicated task today, i need to have a php script connected and upload some files to an SFTP host.. it was going to be set up as a scheduled task on windows. At first it tried looking for a class on php that would allow me to such that but upon searching most of it is for php5..
It is for a scheduled task on windows.. which i can run using a user account.. so i thought why not use a commandline SFTP client to do the uploading for me. First SFTP Client that came to mind was WinSCP. WinSCP is a free SCP, SFTP client for windows. I was not exactly sure if that will do what i need done.. After a couple of hours of sorting through the online documentation i found out that i can create scripts to be executed on WinSCP3 and that it has one program i can execute on the command line.. http://winscp.net/eng/docs/scripting
What i did is create some sort of template for the script i need winscp3 to run.. I added some tags to it.. I used [FILENAME].. I then had php using preg_replace.. replace all instances of [FILENAME] with the filename of the file i need uploaded… in my case a CSV file that is generated by PHP.. Then i had php write the script on the temp filename.. followed by and exec that executes winscp3.com with /script=example.txt as an argument.
On an important note.. You need to login first and accept some sort of key using the GUI before the command line can work..
