{"id":110361,"date":"2018-01-31T07:31:23","date_gmt":"2018-01-31T07:31:23","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=110361"},"modified":"2019-10-01T11:36:58","modified_gmt":"2019-10-01T11:36:58","slug":"using-python-ftplib-library-file-transfer","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/","title":{"rendered":"Using Python ftplib library for File transfer"},"content":{"rendered":"<p>As python have the rich set of library for doing task automation when it comes to file transfer over FTP server there are many libraries available in python like ftplib, ftputil, paramiko, fabric etc.<\/p>\n<p>In this article, i am going to explain that how you can use ftplib python library for file transfer over an FTP server.<\/p>\n<p>&nbsp;<\/p>\n<p>Using ftplib library you can perform a variety of FTP jobs automation, You can seamlessly connect to an FTP server to retrieving files and manipulate them locally.<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"brush:py\">from ftplib import FTP\nftp_obj = FTP()\n\nserveruri='192.168.1.199'\nserverport='21'\nftp.connect(serveruri, serverport)\n\nserveruser='ftp-test'\nserverpassword='ftp-test12#'\nftp_obj.login(user = serveruser, passwd = serverpassword)\n\nftp_obj.retrlines('LIST') # list directory contents\n<\/pre>\n<h6>##########################################<\/h6>\n<p><strong>FTP Methods:<\/strong><\/p>\n<p><em>==&gt;FTP.connect(host[, port[, timeout]])<\/em><\/p>\n<p>This use to establish a connection to the given host and port.<\/p>\n<p>In case no port provided then the default port number is 21 will use as per FTP protocol specification.<\/p>\n<p>&nbsp;<\/p>\n<p><em>==&gt;FTP.getwelcome()<\/em><\/p>\n<p>This use to get the welcome message sent by the server.<\/p>\n<p>&nbsp;<\/p>\n<p>==&gt;FTP.cwd(pathname)<\/p>\n<p>To change directory using cwd.<\/p>\n<p>Like:<\/p>\n<pre class=\"brush:py\">serverdirectorypath='\/files'\nftp_obj.cwd(serverdirectorypath)<\/pre>\n<p>&nbsp;<\/p>\n<p>==&gt;FTP.retrbinary(command, callback[, maxblocksize[, rest]])<\/p>\n<p>This use to retrieve a file in form of binary transfer mode.<br \/>\nLike:<\/p>\n<pre class=\"brush:py\">ftp.retrbinary('RETR %s'%serverfilepath, open(localfilepath, 'wb').write)<\/pre>\n<p>&nbsp;<\/p>\n<p>==&gt;FTP.storbinary(command, fp[, blocksize, callback, rest])<\/p>\n<p>This use to upload the data over the server.<\/p>\n<pre class=\"brush:py\">ftp_obj.storbinary('STOR %s'%serverfilepath, = open(localfilepath, 'rb'))<\/pre>\n<p>&nbsp;<\/p>\n<p>==&gt;FTP.retrlines(command[, callback])<\/p>\n<p><span style=\"text-decoration: underline\">Like:<\/span><\/p>\n<pre class=\"brush:py\">ftp_obj.retrlines('LIST')<\/pre>\n<p>To retrieve a file or directory data listing.<\/p>\n<p>&nbsp;<\/p>\n<p>==&gt;FTP.delete(filename)<\/p>\n<pre class=\"brush:py\">ftp_obj.delete(serverfilepath)<\/pre>\n<p>To delete the file (filename) from the server.<\/p>\n<p>&nbsp;<\/p>\n<p>==&gt;FTP.mkd(pathname)<\/p>\n<p>To create a new directory on given path (pathname).<\/p>\n<pre class=\"brush:py\">ftp_obj.mkd(serverdirectorypath)<\/pre>\n<p>&nbsp;<\/p>\n<p>For more detailed elaboration, please see the<a href=\"https:\/\/docs.python.org\/2\/library\/ftplib.html\"> official python documentation<\/a><\/p>\n<p>That\u2019s all for today. I hope this blog will help you. I\u2019d be very grateful if you\u2019d write your opinions, comments, and suggestions to keep the page updated and interesting.<\/p>\n<p>You may also like our post on&nbsp;<a href=\"https:\/\/webkul.com\/blog\/using-io-for-creating-file-object\/\">using StringIO and BytesIO for managing data file object <\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As python have the rich set of library for doing task automation when it comes to file transfer over FTP server there are many libraries available in python like ftplib, ftputil, paramiko, fabric etc. In this article, i am going to explain that how you can use ftplib python library for file transfer over an <a href=\"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":86,"featured_media":45511,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2007],"tags":[6119,6120,3324],"class_list":["post-110361","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-odoo","tag-ftp","tag-ftplib","tag-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Using Python ftplib library for File transfer - Webkul Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using Python ftplib library for File transfer - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"As python have the rich set of library for doing task automation when it comes to file transfer over FTP server there are many libraries available in python like ftplib, ftputil, paramiko, fabric etc. In this article, i am going to explain that how you can use ftplib python library for file transfer over an [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-31T07:31:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-10-01T11:36:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/04\/Odoo-Code-Snippet-banner.png\" \/>\n\t<meta property=\"og:image:width\" content=\"825\" \/>\n\t<meta property=\"og:image:height\" content=\"260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Prakash Kumar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prakash Kumar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/\"},\"author\":{\"name\":\"Prakash Kumar\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/8b41d806aa1c7ec81f958437fac62e5b\"},\"headline\":\"Using Python ftplib library for File transfer\",\"datePublished\":\"2018-01-31T07:31:23+00:00\",\"dateModified\":\"2019-10-01T11:36:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/\"},\"wordCount\":299,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/04\/Odoo-Code-Snippet-banner.png\",\"keywords\":[\"ftp\",\"ftplib\",\"python\"],\"articleSection\":[\"Odoo\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/\",\"url\":\"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/\",\"name\":\"Using Python ftplib library for File transfer - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/04\/Odoo-Code-Snippet-banner.png\",\"datePublished\":\"2018-01-31T07:31:23+00:00\",\"dateModified\":\"2019-10-01T11:36:58+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/04\/Odoo-Code-Snippet-banner.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/04\/Odoo-Code-Snippet-banner.png\",\"width\":825,\"height\":260},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using Python ftplib library for File transfer\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/8b41d806aa1c7ec81f958437fac62e5b\",\"name\":\"Prakash Kumar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/0423ba8e78c94fb466768b44982d402aec0a1bb0ea274e7907672f740c41d776?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/0423ba8e78c94fb466768b44982d402aec0a1bb0ea274e7907672f740c41d776?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Prakash Kumar\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/prakash-kumar163\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using Python ftplib library for File transfer - Webkul Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/","og_locale":"en_US","og_type":"article","og_title":"Using Python ftplib library for File transfer - Webkul Blog","og_description":"As python have the rich set of library for doing task automation when it comes to file transfer over FTP server there are many libraries available in python like ftplib, ftputil, paramiko, fabric etc. In this article, i am going to explain that how you can use ftplib python library for file transfer over an [...]","og_url":"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2018-01-31T07:31:23+00:00","article_modified_time":"2019-10-01T11:36:58+00:00","og_image":[{"width":825,"height":260,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/04\/Odoo-Code-Snippet-banner.png","type":"image\/png"}],"author":"Prakash Kumar","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Prakash Kumar","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/"},"author":{"name":"Prakash Kumar","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/8b41d806aa1c7ec81f958437fac62e5b"},"headline":"Using Python ftplib library for File transfer","datePublished":"2018-01-31T07:31:23+00:00","dateModified":"2019-10-01T11:36:58+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/"},"wordCount":299,"commentCount":2,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/04\/Odoo-Code-Snippet-banner.png","keywords":["ftp","ftplib","python"],"articleSection":["Odoo"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/","url":"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/","name":"Using Python ftplib library for File transfer - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/04\/Odoo-Code-Snippet-banner.png","datePublished":"2018-01-31T07:31:23+00:00","dateModified":"2019-10-01T11:36:58+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/04\/Odoo-Code-Snippet-banner.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/04\/Odoo-Code-Snippet-banner.png","width":825,"height":260},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/using-python-ftplib-library-file-transfer\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Using Python ftplib library for File transfer"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/8b41d806aa1c7ec81f958437fac62e5b","name":"Prakash Kumar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/0423ba8e78c94fb466768b44982d402aec0a1bb0ea274e7907672f740c41d776?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0423ba8e78c94fb466768b44982d402aec0a1bb0ea274e7907672f740c41d776?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Prakash Kumar"},"url":"https:\/\/webkul.com\/blog\/author\/prakash-kumar163\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/110361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/86"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=110361"}],"version-history":[{"count":10,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/110361\/revisions"}],"predecessor-version":[{"id":200904,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/110361\/revisions\/200904"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media\/45511"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=110361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=110361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=110361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}