{"id":1226,"date":"2016-05-03T20:40:04","date_gmt":"2016-05-03T20:40:04","guid":{"rendered":"http:\/\/62.131.51.129\/?p=1226"},"modified":"2016-05-03T20:40:04","modified_gmt":"2016-05-03T20:40:04","slug":"bash-script-to-upload-file","status":"publish","type":"post","link":"http:\/\/archief.van-maanen.com\/?p=1226","title":{"rendered":"Bash script to upload file"},"content":{"rendered":"<p>In many environment, we have a situation whereby a file must be transmitted via a script from one server to another. Assume we have a linux environment where Bash is installed. In that case, a sftp connection can be used. The principle is relatively simple: a sftp session is started from one machine to another. Via ftp commands, the file is transferred. But one may prefer to have a batch script that takes care of setting up the connection, transferring the file and closing the connection.<br \/>\nI assume that the two machines have set up a connection via private\/ public keys. This avoids the necessity of having to provide a password.<br \/>\nOne might use:<\/p>\n<pre>\n#!\/usr\/bin\n\nsftp_user=\"pi\"\nsftp_machine=\"192.168.2.11\"\n\neval sftp -b ftpregel $sftp_user@$sftp_machine\n\nrc=$?\necho $rc\n        if [ $rc -ne 0 ]\n        then\n                echo \"$PROGNAME: ERROR in sftp!\"\n        fi\n<\/pre>\n<p>and the ftpregel that contains the ftp command looks like:<\/p>\n<pre>\nput GeileBeer.log\nquit\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In many environment, we have a situation whereby a file must be transmitted via a script from one server to another. Assume we have a linux environment where Bash is installed. In that case, a sftp connection can be used. The principle is relatively simple: a sftp session is started from one machine to another. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1227,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1226","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/1226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1226"}],"version-history":[{"count":0,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/1226\/revisions"}],"wp:attachment":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1226"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}