{"_id":"54fda39021538c21006c49b0","githubsync":"","project":"545e249c7ca5470800b3a1b2","user":"545e246f7ca5470800b3a1b1","__v":0,"version":{"_id":"54fda38e21538c21006c49a6","__v":3,"forked_from":"54eb4535615ffc19003059f0","project":"545e249c7ca5470800b3a1b2","createdAt":"2015-03-09T13:43:42.927Z","releaseDate":"2015-03-09T13:43:42.927Z","categories":["54fda38f21538c21006c49a7","54fda38f21538c21006c49a8","54fda38f21538c21006c49a9","54fda38f21538c21006c49aa","54fda38f21538c21006c49ab","54fda3d347f93619001d2ae2","54fea8975c4ab10d00ef4279"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"0.5.0","version":"0.5.0"},"category":{"_id":"54fda38f21538c21006c49aa","version":"54fda38e21538c21006c49a6","__v":1,"pages":["54fda39021538c21006c49b0","54fda39021538c21006c49b1","54fda39021538c21006c49b2"],"project":"545e249c7ca5470800b3a1b2","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-12-03T16:33:32.245Z","from_sync":false,"order":2,"slug":"transports","title":"Transports"},"metadata":{"title":"","description":"","image":[]},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2014-12-03T16:34:42.810Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"auth":"never","params":[],"url":""},"isReference":false,"order":0,"body":"The SCP transport allows transfer of files and directories from the localhost to a remote host or from a remote host to the localhost.\n\nThe SCP transport uses the SSH private key defined at the job or host level.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"copy\"\n}\n[/block]\nUnlike the `move` verb, `copy` preserves the input resource during the transfer. It also means that subsequent agents will assume the resource is still located on the original host.\n\n## Copy a file\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"host \\\"remote\\\", hostname: \\\"host.example.com\\\", private_key: \\\"~/.ssh/electric_sheep_rsa\\\"\\n\\njob \\\"daily-report\\\" do\\n  resource \\\"file\\\", path: \\\"/var/daily/report\\\", host: \\\"remote\\\"\\n  copy to: \\\"localhost\\\", using: \\\"scp\\\", as: \\\"operator\\\"\\nend\",\n      \"language\": \"ruby\",\n      \"name\": \"Sheepfile\"\n    }\n  ]\n}\n[/block]\n## Recursively copy a directory\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"host \\\"app\\\", hostname: \\\"app.example.com\\\", private_key: \\\"~/.ssh/electric_sheep_rsa\\\"\\n\\njob \\\"user-uploads\\\" do\\n  resource \\\"directory\\\", path: \\\"/var/www/uploads\\\", host: \\\"app\\\"\\n  copy to: \\\"localhost\\\", using: \\\"scp\\\", as: \\\"operator\\\"\\nend\",\n      \"language\": \"ruby\",\n      \"name\": \"Sheepfile\"\n    }\n  ]\n}\n[/block]\n_In most cases, you'd better create an archive containing a copy of the directory (see [Files & Directories compression](doc:compression)) and move it as a single file than to recursively copy directories._\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"move\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"danger\",\n  \"title\": \"Destructive action\",\n  \"body\": \"Unlike the `copy` verb, `move` destroys the input resource once the file or directory has been copied to the target host.\"\n}\n[/block]\n## Move a file\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"host \\\"remote\\\", hostname: \\\"host.example.com\\\", private_key: \\\"~/.ssh/electric_sheep_rsa\\\"\\n\\njob \\\"daily-report\\\" do\\n  resource \\\"file\\\", path: \\\"/var/daily/report\\\", host: \\\"remote\\\"\\n  move to: \\\"localhost\\\", using: \\\"scp\\\", as: \\\"operator\\\"\\nend\",\n      \"language\": \"ruby\",\n      \"name\": \"Sheepfile\"\n    }\n  ]\n}\n[/block]\n## Recursively move a directory\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"host \\\"app\\\", hostname: \\\"app.example.com\\\", private_key: \\\"~/.ssh/electric_sheep_rsa\\\"\\n\\njob \\\"log-archives\\\" do\\n  resource \\\"directory\\\", path: \\\"/var/log/archives\\\", host: \\\"app\\\"\\n  move to: \\\"localhost\\\", using: \\\"scp\\\", as: \\\"operator\\\"\\nend\",\n      \"language\": \"ruby\",\n      \"name\": \"Sheepfile\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Options\"\n}\n[/block]\n\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Option\",\n    \"h-1\": \"Description\",\n    \"0-0\": \"`as`\",\n    \"0-1\": \"The user account to use when opening the SSH/SCP connection to the remote host\",\n    \"0-2\": \"Required: yes\",\n    \"1-0\": \"`to`\",\n    \"1-1\": \"The target host: `localhost` or an existing remote host\",\n    \"1-2\": \"Required: yes\"\n  },\n  \"cols\": 3,\n  \"rows\": 2\n}\n[/block]","excerpt":"Transfer files and directories using the SCP protocol","slug":"scp-secure-copy--ssh","type":"basic","title":"SCP"}

SCP

Transfer files and directories using the SCP protocol

The SCP transport allows transfer of files and directories from the localhost to a remote host or from a remote host to the localhost. The SCP transport uses the SSH private key defined at the job or host level. [block:api-header] { "type": "basic", "title": "copy" } [/block] Unlike the `move` verb, `copy` preserves the input resource during the transfer. It also means that subsequent agents will assume the resource is still located on the original host. ## Copy a file [block:code] { "codes": [ { "code": "host \"remote\", hostname: \"host.example.com\", private_key: \"~/.ssh/electric_sheep_rsa\"\n\njob \"daily-report\" do\n resource \"file\", path: \"/var/daily/report\", host: \"remote\"\n copy to: \"localhost\", using: \"scp\", as: \"operator\"\nend", "language": "ruby", "name": "Sheepfile" } ] } [/block] ## Recursively copy a directory [block:code] { "codes": [ { "code": "host \"app\", hostname: \"app.example.com\", private_key: \"~/.ssh/electric_sheep_rsa\"\n\njob \"user-uploads\" do\n resource \"directory\", path: \"/var/www/uploads\", host: \"app\"\n copy to: \"localhost\", using: \"scp\", as: \"operator\"\nend", "language": "ruby", "name": "Sheepfile" } ] } [/block] _In most cases, you'd better create an archive containing a copy of the directory (see [Files & Directories compression](doc:compression)) and move it as a single file than to recursively copy directories._ [block:api-header] { "type": "basic", "title": "move" } [/block] [block:callout] { "type": "danger", "title": "Destructive action", "body": "Unlike the `copy` verb, `move` destroys the input resource once the file or directory has been copied to the target host." } [/block] ## Move a file [block:code] { "codes": [ { "code": "host \"remote\", hostname: \"host.example.com\", private_key: \"~/.ssh/electric_sheep_rsa\"\n\njob \"daily-report\" do\n resource \"file\", path: \"/var/daily/report\", host: \"remote\"\n move to: \"localhost\", using: \"scp\", as: \"operator\"\nend", "language": "ruby", "name": "Sheepfile" } ] } [/block] ## Recursively move a directory [block:code] { "codes": [ { "code": "host \"app\", hostname: \"app.example.com\", private_key: \"~/.ssh/electric_sheep_rsa\"\n\njob \"log-archives\" do\n resource \"directory\", path: \"/var/log/archives\", host: \"app\"\n move to: \"localhost\", using: \"scp\", as: \"operator\"\nend", "language": "ruby", "name": "Sheepfile" } ] } [/block] [block:api-header] { "type": "basic", "title": "Options" } [/block] [block:parameters] { "data": { "h-0": "Option", "h-1": "Description", "0-0": "`as`", "0-1": "The user account to use when opening the SSH/SCP connection to the remote host", "0-2": "Required: yes", "1-0": "`to`", "1-1": "The target host: `localhost` or an existing remote host", "1-2": "Required: yes" }, "cols": 3, "rows": 2 } [/block]