{"id":14497,"date":"2024-08-29T14:04:49","date_gmt":"2024-08-29T06:04:49","guid":{"rendered":"http:\/\/xinyiworld.top\/wordpress_it\/?p=14497"},"modified":"2024-08-29T14:07:56","modified_gmt":"2024-08-29T06:07:56","slug":"sftp%e6%96%87%e4%bb%b6%e4%b8%8a%e4%bc%a0","status":"publish","type":"post","link":"http:\/\/xinyiworld.top\/wordpress_it\/?p=14497","title":{"rendered":"sftp(\u6587\u4ef6\u4e0a\u4f20)"},"content":{"rendered":"<ul>\n<li>\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4<\/li>\n<\/ul>\n<pre><code class=\"language-bash\">package main\n\nimport (\n    &quot;fmt&quot;\n    &quot;github.com\/pkg\/sftp&quot;\n    &quot;golang.org\/x\/crypto\/ssh&quot;\n    &quot;time&quot;\n)\n\nfunc main() {\n    \/\/ \u521b\u5efaSSH\u5ba2\u6237\u7aef\u914d\u7f6e\n    config := &amp;ssh.ClientConfig{\n        Timeout:         time.Second * 5, \/\/ \u8bbe\u7f6eSSH\u8fde\u63a5\u8d85\u65f6\u65f6\u95f4\u4e3a5\u79d2\n        User:            &quot;username&quot;,\n        HostKeyCallback: ssh.InsecureIgnoreHostKey(), \/\/ \u5047\u8bbe\u4e0d\u9a8c\u8bc1host key\n    }\n\n    \/\/ \u8bbe\u7f6e\u5bc6\u7801\u6216\u8005\u5bc6\u94a5\u8ba4\u8bc1\n    password := &quot;password&quot;\n    config.Auth = []ssh.AuthMethod{\n        ssh.Password(password),\n    }\n\n    \/\/ \u5efa\u7acbSSH\u8fde\u63a5\n    sshClient, err := ssh.Dial(&quot;tcp&quot;, &quot;remote.host:22&quot;, config)\n    if err != nil {\n        panic(&quot;Failed to dial: &quot; + err.Error())\n    }\n    defer sshClient.Close()\n\n    \/\/ \u5f00\u542fSFTP\u4f1a\u8bdd\n    sftpClient, err := sftp.NewClient(sshClient)\n    if err != nil {\n        panic(&quot;Failed to start SFTP subsystem: &quot; + err.Error())\n    }\n    defer sftpClient.Close()\n\n    \/\/ \u6b64\u5904\u53ef\u4ee5\u8fdb\u884c\u6587\u4ef6\u64cd\u4f5c\n    \/\/ ...\n}<\/code><\/pre>\n<button class=\"simplefavorite-button\" data-postid=\"14497\" data-siteid=\"1\" data-groupid=\"1\" data-favoritecount=\"0\" style=\"\">\u6536\u85cf <i class=\"sf-icon-star-empty\"><\/i><\/button>","protected":false},"excerpt":{"rendered":"<p>\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4 package main import ( &quot;fmt&quot; &#038;quot [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[532],"tags":[],"_links":{"self":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/14497"}],"collection":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14497"}],"version-history":[{"count":1,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/14497\/revisions"}],"predecessor-version":[{"id":14498,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/14497\/revisions\/14498"}],"wp:attachment":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14497"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}