{"id":1028,"date":"2020-01-28T14:41:41","date_gmt":"2020-01-28T14:41:41","guid":{"rendered":"http:\/\/blog.successionua.com\/?p=1028"},"modified":"2020-01-28T15:37:42","modified_gmt":"2020-01-28T15:37:42","slug":"python-%d1%81%d0%ba%d1%80%d0%b8%d0%bf%d1%82%d0%b8%d0%bd%d0%b3-%d0%ba%d0%b0%d0%ba-%d0%b7%d0%b0%d0%b9%d1%82%d0%b8-%d0%bd%d0%b0-ftp-%d0%b8%d0%bb%d0%b8-ftps","status":"publish","type":"post","link":"https:\/\/geckich.space\/?p=1028","title":{"rendered":"Python \u0441\u043a\u0440\u0438\u043f\u0442\u0438\u043d\u0433: \u043a\u0430\u043a \u0437\u0430\u0439\u0442\u0438 \u043d\u0430 FTP \u0438\u043b\u0438 FTPS"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u0411\u044b\u0432\u0430\u0435\u0442 \u043d\u0443\u0436\u043d\u043e \u0447\u0442\u043e-\u0442\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c\/\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043d\u0430 \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 FTP \u0438\u043b\u0438 FTPS (\u043d\u0435 \u043f\u0443\u0442\u0430\u0442\u044c \u0441 SFTP) \u0432 \u0441\u043a\u0440\u0438\u043f\u0442\u0435 \u043d\u0430 \u043f\u0430\u0439\u0442\u043e\u043d\u0435.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><em>from <\/em>ftplib <em>import <\/em>FTP_TLS\n<em>from <\/em>ftplib <em>import <\/em>FTP<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u0417\u0430\u0434\u0430\u0451\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a FTP \u0445\u043e\u0441\u0442\u0443:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">host = \"some_ftp.com\"\nport = 21\nusername = \"username\"\npassword = \"password\"<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u043e\u0431\u044b\u0447\u043d\u043e\u043c\u0443 FTP (\u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u043d\u0430 \u0434\u0438\u0441\u043a):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ftp = FTP(host)\nftp.login(username, password)\n<em>try<\/em>:\n    handle = open('\/path_to_local_file\/filename', 'wb')\n    ftp.retrbinary('RETR \/path_to_remote_file\/filename, handle.write)\n    handle.close()\n<em>except<\/em>:\n    pass\nftp.quit()<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u0412\u0441\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 FTP \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <a href=\"https:\/\/www.w3.org\/Protocols\/rfc959\/4_FileTransfer.html\">\u0442\u0430\u043a\u043e\u0439<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u041e\u0441\u043e\u0432\u043d\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<br>RETR &#8211; \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0444\u0430\u0439\u043b \u0441 FTP \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0438\u043b\u0438 \u043f\u043e \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u0443 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b;<br>LIST &#8211; \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0444\u0430\u0439\u043b\u043e\u0432\/\u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0439 \u0432 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u0438\u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e;<br>NLST &#8211; \u0442\u043e \u0436\u0435, \u0447\u0442\u043e \u0438 LIST, \u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043c\u0435\u043d\u0430 \u0444\u0430\u0439\u043b\u043e\u0432\/\u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0439;<br>STOR &#8211; \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0441 \u043f\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u044c\u044e \u0444\u0430\u0439\u043b \u043d\u0430 FTP-\u0441\u0435\u0440\u0432\u0435\u0440;<br>\u0438 \u0434\u0440\u0443\u0433\u0438\u0435<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a FTPS \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u0445\u043e\u0436\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><em>try<\/em>:\n    handle = open('\/path_to_local_file\/filename', 'wb')\n    ftps = FTP_TLS(host)\n    ftps.login(username, password)\n    ftps.prot_p()\n    ftps.retrbinary('RETR \/path_to_remote_file\/filename', handle.write)\n    ftps.quit()\n    handle.close()\n<em>except<\/em>:\n    pass<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b FTP_TLS \u043d\u0443\u0436\u0435\u043d \u043f\u0430\u0439\u0442\u043e\u043d 2.7+, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0442\u043e\u043b\u044c\u043a\u043e 2.6, \u0442\u043e \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0434\u043d\u043e \u0438\u0437 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e:<br>1. \u0414\u043e\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0430\u0439\u0442\u043e\u043d 2.7, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u0430\u043a \u043e\u043f\u0438\u0441\u0430\u043d\u043e <a href=\"https:\/\/docs.cloudera.com\/documentation\/enterprise\/6\/6.0\/topics\/install_python_27.html\">\u0437\u0434\u0435\u0441\u044c<\/a> \u0434\u043b\u044f Oracle Linux 6:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0420\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u043c\u00a0<strong>\/etc\/yum.repos.d\/public-yum-ol6.repo<\/strong>\u00a0\u0438 \u0443\u0431\u0435\u0436\u0434\u0430\u0435\u043c\u0441\u044f, \u0447\u0442\u043e <strong>enabled=1<\/strong> \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u0435:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[ol6_software_collections]\nname=Software Collection Library release 3.0 packages for Oracle Linux 6 (x86_64)\nbaseurl=http:\/\/yum.oracle.com\/repo\/OracleLinux\/OL6\/SoftwareCollections\/x86_64\/\ngpgkey=file:\/\/\/etc\/pki\/rpm-gpg\/RPM-GPG-KEY-oracle\ngpgcheck=1\nenabled=1<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u0414\u0430\u043b\u0435\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043e\u0442 \u0440\u0443\u0442\u0430\/\u0441\u0443\u0434\u043e:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">yum install scl-utils\nyum install python27\nsource \/opt\/rh\/python27\/enable\npython --version<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u0415\u0441\u043b\u0438 \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u043f\u043e cron (\u0430 \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0442\u0430\u043a \u0438 \u0431\u0443\u0434\u0435\u0442) \u0432\u044b\u0431\u0438\u0432\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443 \u0432\u0438\u0434\u0430:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u0422\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0443\u0442\u044c \u043a \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u0432 <strong>\/etc\/ld.so.conf<\/strong> \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <strong>ldconfig<\/strong>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0430\u043c\u0430 \u0432\u0441\u0451 \u043f\u0440\u043e\u043f\u0438\u0448\u0435\u0442.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0438\u043b\u0438<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. C\u043a\u0430\u0447\u0430\u0442\u044c \u0434\u0438\u0441\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u0432 \u043f\u0430\u0439\u0442\u043e\u043d\u0430 2.7 \u043e\u0442\u0441\u044e\u0434\u0430 \u0438 \u0432\u044b\u0442\u0430\u0449\u0438\u0442\u044c \u0444\u0430\u043b ftplib.py \u0438 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u043f\u0430\u043f\u043a\u0443 \u0441\u043e \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u043c (\u0435\u0441\u043b\u0438 \u0441\u043a\u0440\u0438\u043f\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043f\u043e cron, \u0442\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">wget http:\/\/www.python.org\/ftp\/python\/2.7.1\/Python-2.7.1.tgz\ntar -zxvf Python-2.7.1.tgz Python-2.7.1\/Lib\/ftplib.py\ncp Python-2.7.1\/Lib\/ftplib.py \/path_to_script\/<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u0438\u043b\u0438<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3. \u0417\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u043d\u0430 FTPS \u0432\u044b\u0437\u044b\u0432\u0430\u044f bash \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 lftp \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u043e\u0434\u0443\u043b\u044f subprocess.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0421\u0441\u044b\u043b\u043a\u0438:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><a href=\"https:\/\/docs.python.org\/3\/library\/ftplib.html\">https:\/\/docs.python.org\/3\/library\/ftplib.html<\/a><\/li><li><a href=\"https:\/\/stackoverflow.com\/questions\/11573817\/how-to-download-a-file-via-ftp-with-python-ftplib\">https:\/\/stackoverflow.com\/questions\/11573817\/how-to-download-a-file-via-ftp-with-python-ftplib<\/a><\/li><li><a href=\"https:\/\/stackoverflow.com\/questions\/20842732\/libpython2-7-so-1-0-cannot-open-shared-object-file-no-such-file-or-directory\">https:\/\/stackoverflow.com\/questions\/20842732\/libpython2-7-so-1-0-cannot-open-shared-object-file-no-such-file-or-directory<\/a><\/li><li><a href=\"https:\/\/docs.cloudera.com\/documentation\/enterprise\/6\/6.0\/topics\/install_python_27.html\">https:\/\/docs.cloudera.com\/documentation\/enterprise\/6\/6.0\/topics\/install_python_27.html<\/a><\/li><\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u0411\u044b\u0432\u0430\u0435\u0442 \u043d\u0443\u0436\u043d\u043e \u0447\u0442\u043e-\u0442\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c\/\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043d\u0430 \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 FTP \u0438\u043b\u0438 FTPS (\u043d\u0435 \u043f\u0443\u0442\u0430\u0442\u044c \u0441 SFTP) \u0432 \u0441\u043a\u0440\u0438\u043f\u0442\u0435 \u043d\u0430 \u043f\u0430\u0439\u0442\u043e\u043d\u0435. \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438: from ftplib import FTP_TLS from ftplib import FTP \u0417\u0430\u0434\u0430\u0451\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a FTP \u0445\u043e\u0441\u0442\u0443: host = &#8220;some_ftp.com&#8221; port = 21 username = &#8220;username&#8221; password = &#8220;password&#8221; \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u043e\u0431\u044b\u0447\u043d\u043e\u043c\u0443 FTP (\u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b &hellip; <a href=\"https:\/\/geckich.space\/?p=1028\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Python \u0441\u043a\u0440\u0438\u043f\u0442\u0438\u043d\u0433: \u043a\u0430\u043a \u0437\u0430\u0439\u0442\u0438 \u043d\u0430 FTP \u0438\u043b\u0438 FTPS<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[10,11,7,1],"tags":[25,118,119,122,48,55,116,121,120],"class_list":["post-1028","post","type-post","status-publish","format-standard","hentry","category-linux","category-programming","category-sysadmin","category-uncategorized","tag-console","tag-ftp","tag-ftplib","tag-ldconfig","tag-linux","tag-oracle-linux","tag-python","tag-python-2-6","tag-python-2-7"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/geckich.space\/index.php?rest_route=\/wp\/v2\/posts\/1028","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geckich.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geckich.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geckich.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/geckich.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1028"}],"version-history":[{"count":13,"href":"https:\/\/geckich.space\/index.php?rest_route=\/wp\/v2\/posts\/1028\/revisions"}],"predecessor-version":[{"id":1044,"href":"https:\/\/geckich.space\/index.php?rest_route=\/wp\/v2\/posts\/1028\/revisions\/1044"}],"wp:attachment":[{"href":"https:\/\/geckich.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1028"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geckich.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1028"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geckich.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1028"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}