Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I'm trying to write a bash script that uploads a file to a server. How can I achieve this? Is a bash script the right thing to use for this? Below are two answers.
Subscribe to RSS
Second is an explanation of how to run ftp in batch mode. For more details on setting up keys and moving files to the server with RSYNC, which is useful if you have a lot of files to move, or if you sometimes get just one new file among a set of random files, take a look at:. If you can use SFTP with keys to gain the benefit of a secured connection, there are two tricks I've used to execute commands.
If you understand that FTP is insecure and more limited and you really really want to script it The "-n" to ftp ensures that the command won't try to get the password from the current terminal.
The binary command will set it to binary mode which helps if you are transferring something other than a text file. You can use a heredoc to do this e. A useful tip for spawning any process, not just ftp! Note that this saves spawning a separate process echo, cat etc.
Not a major resource saving, but worth bearing in mind. The ftp command isn't designed for scripts, so controlling it is awkward, and getting its exit status is even more awkward.
Curl is made to be scriptable, and also has the merit that you can easily switch to other protocols later by just modifying the URL. If you put your FTP credentials in your. If you must, you can specify username and password directly on the command line using --user username:password instead of --netrc.discover-migme.hipwee.com/28603-cell-phone.php
Subscribe to RSS
Listen now. Learn more. How to upload FTP files to server in a bash script? Ask Question. Asked 9 years, 10 months ago. Active 6 months ago. Viewed k times. Christian Strempfer 5, 4 4 gold badges 39 39 silver badges 69 69 bronze badges. Andrew Andrew k gold badges silver badges bronze badges. The solution is not for ftp protocole but for ssh. So, an example command is: ssh username hostname.
I would like to do this! Can you please expand on how I can do this? I need to do some things with ssh after uploading the file. Can this be done in one session? While it was useful advice for the OP, it shouldn't be the accepted answer. Some of the other posters have added binary mode i.
- FileZilla – Software-Tipp!
- How to Upload or Download Files/Directories Using sFTP in Linux;
- disinstallare office 2008 per mac.
- Alles, was ein FTP-Programm braucht.
- How do you upload your files to a web server?!
- Subscribe to RSS.
- best proxy browser for mac.
S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge. Your name can also be listed here. Got a tip? Submit it here to become an TecMint author. Your email address will not be published.
Save my name, email, and website in this browser for the next time I comment. Notify me of followup comments via e-mail. You can also subscribe without commenting. This site uses Akismet to reduce spam. Learn how your comment data is processed. How to Install Nagios 4. Ending In: 3 days. Ending In: 4 days. FTP 2. Download Directory using sFTP.
Support us by taking our online Linux courses We are thankful for your never ending support. October 10, at pm. Aaron Kili says:. October 12, at pm. Got something to say? Join the discussion. Cancel reply Your email address will not be published. I TecMint :.