If you are using this code to download an image to your computer (and not a server), I would use Python instead since it is suited for server side development as well as little scripts you want to schedule on your computer.
If you would like to continue with PHP, hielo has the right idea. Although I think cURL can handle FTP if you use an FTP URL like ftp://user:pass@host:port, but I'm not sure.
On second glance I noticed that you provided us with port 22, which happens to be the port for SSH (most likely for SFTP use). If you are using SSH/SFTP, you will need to use PHP's SSH functions.
I can't say which one is "better" than the other. My suggestion to you would be to use whichever of the two you find easier to understand. Down the road you may need to come back to your script and make changes. Understanding well what your code does will make your job easier.
root = tkinter.Tk()
buttons=[i for i in range(10)]
#If specific button is pressed, output "YES"
for num in buttons: