{"id":73,"date":"2009-02-07T05:52:58","date_gmt":"2009-02-07T12:52:58","guid":{"rendered":"http:\/\/www.zulutown.com\/blog\/?p=73"},"modified":"2009-02-07T05:52:58","modified_gmt":"2009-02-07T12:52:58","slug":"copying-files-between-clients-and-servers-over-ssh-using-scp","status":"publish","type":"post","link":"http:\/\/www.zulutown.com\/blog\/2009\/02\/07\/copying-files-between-clients-and-servers-over-ssh-using-scp\/","title":{"rendered":"Copying Files between Clients and Servers over ssh using scp"},"content":{"rendered":"<p>It&#8217;s quite common to need to upload or download file between one or more servers and the local computer.<\/p>\n<p>If it&#8217;s available a <em>ssh access<\/em> on the servers, using <code>scp<\/code> to transfer file from and to the server could be a very good option.<\/p>\n<p>Here&#8217;s its syntax:<\/p>\n<pre>usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]\r\n           [-l limit] [-o ssh_option] [-P port] [-S program]\r\n           [[user@]host1:]file1 ... [[user@]host2:]file2<\/pre>\n<p>A very simple example:<\/p>\n<pre>scp localfilename.txt remoteuser@www.remotehost.com:remotefilename.txt<\/pre>\n<p>The previous example copies <code>localfilename.txt<\/code> from the local directory to the server <code>www.remotehost.com<\/code> using <code>remoteuser<\/code> as the ssh account to authenticate on the remote server. On the remote server the transferred file will be stored as <code>remotefilename.txt<\/code> in the default login directory of <code>remoteuser<\/code>.<\/p>\n<p>Copying file from and to specific directories:<\/p>\n<pre>scp \/localdir\/localfilename.txt remoteuser@www.remotehost.com:\/remotedir\/remotefilename.txt<\/pre>\n<p>Compared to the previous example, in this case, the file is taken from <code>\/localdir\/localfilename.txt<\/code> and stored remotely on <code>\/remotedir\/remotefilename.txt<\/code>.<br \/>\nObviously <code>remoteuser<\/code> should have write permission on the remote directory where the file is going to be written.<\/p>\n<p>In the next case, the authentication is made through a keyfile, this is the syntax:<\/p>\n<pre>scp -i keyfile \/localdir\/localfilename.txt remoteuser@www.remotehost.com:\/remotedir\/remotefilename.txt<\/pre>\n<p>In this case to login as <code>remoteuser<\/code> there will not be a prompt for password, but <code>keyfile<\/code> is used as identity file.<\/p>\n<p>It&#8217;s even possible to copy directly files from one server to another<\/p>\n<pre>scp firstremoteuser@www.firstserver.com:\/filename.txt anotherremoteuser@www.anotherserver.com:\/remotedir\/remotefilename.txt<\/pre>\n<p>Finally one of the best features is to copy recursively directory trees to the remote server:<\/p>\n<pre>scp -r \/localdirectory remoteuser@www.remoteserver.com:\/remotedirectory<\/pre>\n<p>In this case, the whole content of localdirectory is recursively copied into remotedirectory. This can be very useful for moving quickly website structures.<br \/>\nI hope you&#8217;ve found some useful information in this tutorial.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s quite common to need to upload or download file between one or more servers and the local computer. If it&#8217;s available a ssh access on the servers, using scp to transfer file from and to the server could be &hellip; <a href=\"http:\/\/www.zulutown.com\/blog\/2009\/02\/07\/copying-files-between-clients-and-servers-over-ssh-using-scp\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,27],"tags":[31,36,33,32,29,35,30,34],"_links":{"self":[{"href":"http:\/\/www.zulutown.com\/blog\/wp-json\/wp\/v2\/posts\/73"}],"collection":[{"href":"http:\/\/www.zulutown.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zulutown.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zulutown.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zulutown.com\/blog\/wp-json\/wp\/v2\/comments?post=73"}],"version-history":[{"count":2,"href":"http:\/\/www.zulutown.com\/blog\/wp-json\/wp\/v2\/posts\/73\/revisions"}],"predecessor-version":[{"id":75,"href":"http:\/\/www.zulutown.com\/blog\/wp-json\/wp\/v2\/posts\/73\/revisions\/75"}],"wp:attachment":[{"href":"http:\/\/www.zulutown.com\/blog\/wp-json\/wp\/v2\/media?parent=73"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zulutown.com\/blog\/wp-json\/wp\/v2\/categories?post=73"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zulutown.com\/blog\/wp-json\/wp\/v2\/tags?post=73"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}