Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Below are two answers. First is a suggestion to use a more secure/flexible solution like ssh/scp/sftp. Second is an explanation of how to run ftp in batch mode. </p> <h2>A secure solution:</h2> <p>You really should use SSH/SCP/SFTP for this rather than FTP. SSH/SCP have the benefits of being more secure and working with public/private keys which allows it to run without a username or password.</p> <p>You can send a single file:</p> <pre><code>scp &lt;file to upload&gt; &lt;username&gt;@&lt;hostname&gt;:&lt;destination path&gt; </code></pre> <p>Or a whole directory:</p> <pre><code>scp -r &lt;directory to upload&gt; &lt;username&gt;@&lt;hostname&gt;:&lt;destination path&gt; </code></pre> <p>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:</p> <p><a href="http://troy.jdmz.net/rsync/index.html" rel="nofollow noreferrer">http://troy.jdmz.net/rsync/index.html</a></p> <p>You can also execute a single command after sshing into a server:</p> <p>From <code>man ssh</code></p> <blockquote> <p>ssh [...snipped...] hostname [command] If command is specified, it is executed on the remote host instead of a login shell.</p> </blockquote> <p>So, an example command is:</p> <pre><code>ssh username@hostname.example bunzip file_just_sent.bz2 </code></pre> <p>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.</p> <p>First, you can pass commands using echo and pipe</p> <pre><code>echo "put files*.xml" | sftp -p -i ~/.ssh/key_name username@hostname.example </code></pre> <p>You can also use a batchfile with the <code>-b</code> parameter:</p> <pre><code>sftp -b batchfile.txt ~/.ssh/key_name username@hostname.example </code></pre> <h2>An FTP solution, if you really need it:</h2> <p>If you understand that FTP is insecure and more limited and you really really want to script it...</p> <p>There's a great article on this at <a href="http://www.stratigery.com/scripting.ftp.html" rel="nofollow noreferrer">http://www.stratigery.com/scripting.ftp.html</a></p> <pre><code>#!/bin/sh HOST='ftp.example.com' USER='yourid' PASSWD='yourpw' FILE='file.txt' ftp -n $HOST &lt;&lt;END_SCRIPT quote USER $USER quote PASS $PASSWD binary put $FILE quit END_SCRIPT exit 0 </code></pre> <p>The "-n" to ftp ensures that the command won't try to get the password from the current terminal. The other fancy part is the use of a heredoc: the <code>&lt;&lt;END_SCRIPT</code> starts the heredoc and then that exact same <code>END_SCRIPT</code> on the beginning of the line by itself ends the heredoc. The <code>binary</code> command will set it to binary mode which helps if you are transferring something other than a text file.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload