Can I use a Shell Script to do SFTP/SSH to Automate File Uploads

Every so often, I run a XOJO program that creates over a hundred files and places them into about a dozen folders. Using a third-party FTP program, I then upload those files to a third-party web server using SFTP. This basically involves using the FTP software to sign into my account and dragging and dropping the contents of the dozen or so folders into the corresponding folders on the server and waiting for the files to get uploaded.

Can this process be automated with a Shell Script (which I currently know virtually nothing about)? Would it be a good approach?

The script would need to pass my account and password to the web server using ssh and then direct the files from my pc to the proper folders on the web server.

Yes, you can do it with Xojo. My apps send crash data to my FTP server which I can then use to debug problems.

I’ve made some progress based on the Interactive Shell project under /Example Projects/Advanced/Shell/. I can now upload or download individual files or folders by issuing a shell command like:

scp ~/Desktop/filename remoteaccount@serveraddress:/path/filename

which uploads a file from my desktop after I’m prompted for my account password.

  1. But I’m wondering if this can be further streamlined to automatically enter the password, since third-party FTP software somehow does it without my having to do it each time.

  2. Also, is there a limit to how big a file or how many files in a folder can be transferred this way before problems (like timeouts or whatever) are likely to occur?

Chris,

If you would like I can send you a copy of my FTPUpload class that utilizes the CURL function from MonkeyBread software. It allows for SFTP transfers and entering the password, etc.

Might be easier than a shell script. I’m not sure if you use MonkeyBread plugins or not.

I’m interested in this topic, too. I was told that scp is similar to ssh and should work without password.

That would be very helpful Jon. I have an old license for the MonkeyBread plugins so I’ll have to check whether the plugins still works. Thanks.

I was able to do an scp without needing to enter the password. It required generating an ssh-key on my local machine and storing the generated key in the .ssh/authorized_keys file in my account on the remote server. It seems to work well. Now when I enter the scp commands like the one mentioned above, the file is copied without being prompted for a password. Here are the instructions I followed to generate the key:

https://www.tecmint.com/ssh-passwordless-login-using-ssh-keygen-in-5-easy-steps/

MBS Xojo CURL Plugin can do SFTP with either username and password or using private key and username.

Check CURLSMBS class as well as SSH2SessionMBS class for running console commands on another computer.