{ "info": { "author": "Blogg Esse AB", "author_email": "teknik@blogg.se", "bugtrack_url": null, "classifiers": [], "description": "=======\r\nftptool\r\n=======\r\n\r\nHigher-level ftplib\r\n\r\n`ftplib` in itself is a bit raw, as it leaves details about the protocol for\r\nthe user to handle. `ftptool` abstracts that away, and even provides a neat\r\ninterface for file management.\r\n\r\nConnecting & Authenticating\r\n===========================\r\n\r\nCode says more than words, so let's look at an example: connecting.\r\n\r\n>>> a_host = FTPHost.connect(\"ftp.python.org\", user=\"foo\", password=\"bar\")\r\n\r\n`connect` is a classmethod that lets you create an `FTPHost` instance with an\r\nunderlying `ftplib.FTP` instance. \r\n\r\nWorking with Directories\r\n========================\r\n\r\nChanging Working Directory\r\n--------------------------\r\n\r\nChanging and getting the current directory is implemented as a property called\r\n`current_directory`. It is lazy; it won't ask the server which the current\r\ndirectory is until you ask for it.\r\n\r\nNote that since it's a property, this will actually go one level up:\r\n\r\n>>> a_host.current_directory = \"..\"\r\n\r\nSimilarly, this will descend into the \"foo\" directory:\r\n\r\n>>> a_host.current_directory = \"foo\"\r\n\r\nIn most cases, it's easier to just specify absolute paths:\r\n\r\n>>> a_host.current_directory = \"/foo\"\r\n\r\n`current_directory` will always be the server-side representation; when you\r\nchange directory, it ends up sending a ``CWD`` and then a ``PWD`` to get the\r\nresult of the operation (since the FTP protocol doesn't define what the reply\r\ntext to a ``CWD`` is.)\r\n\r\nListing and Walking the Directory Tree\r\n--------------------------------------\r\n\r\nA `os.walk` interface is implemented for walking the directory tree:\r\n\r\n>>> for (dirname, subdirs, files) in a_host.walk(\"/a_dir\"):\r\n... print dirname, \"has file(s)\", \", \".join(files)\r\n...\r\n/a_dir has file(s) foo, bar\r\n/a_dir/other_dir has file(s) hello\r\n/a_dir/some_dir has file(s)\r\n\r\nJust like `os.walk`, you can remove entries in the `subdirs` list to avoid\r\ndescending into them:\r\n\r\n>>> for (dirname, subdirs, files) in a_host.walk(\"/a_dir\"):\r\n... for subdir in subdirs:\r\n... if subdir.startswith(\"other_\"):\r\n... subdirs.remove(subdir)\r\n... print dirname, \"has file(s)\", \", \".join(files)\r\n...\r\n/a_dir has file(s) foo, bar\r\n/a_dir/some_dir has file(s)\r\n\r\nYou can non-recursively list a directory using `listdir`:\r\n\r\n>>> a_host.listdir(\"/a_dir\")\r\n(['other_dir', 'some_dir'], ['foo', 'bar'])\r\n\r\nCreating, Deleting and Renaming\r\n-------------------------------\r\n\r\nThe most simple form of creating a directory is `mkdir`. You simply give it a\r\ndirectory to create, and so it does:\r\n\r\n>>> a_host.mkdir(\"/new_dir\")\r\n\r\nIf you just want to ascertain that a directory is ready, i.e., exists for an\r\nupload, you could use `makedirs` which tries to create every part of the\r\ndirectory, piece by piece.\r\n\r\n>>> a_host.makedirs(\"/a_dir/some_dir/a_new_dir/other_new_dir\")\r\n\r\nWould, hypothetically, create ``a_new_dir`` and ``other_new_dir``.\r\n\r\n`ftptool` implements it by first trying to change directory into the given\r\npath, to see if it exists, and then changes back. If it does, it simply\r\nreturns, otherwise it creates the directories piece by piece.\r\n\r\nUsing the File Proxy\r\n====================\r\n\r\nFiles in `ftptool` are implemented using proxy objects called `FTPFileProxy`.\r\nThey represent a file on a remote host. Using them is easy as pie!\r\n\r\n>>> a_host.file_proxy(\"/a_dir/foo\").download_to_str()\r\n'This is the file \"foo\".'\r\n>>> a_host.file_proxy(\"/a_dir/new_file\").upload_from_str(\"Hello world!\")\r\n\r\nThe Three Upload & Download Methods\r\n-----------------------------------\r\n\r\n`ftptool` provides three ways of uploading or downloading files:\r\n* to/from_str: using a str object,\r\n* to/from_file: using a filename,\r\n* and the default: using a file-like object.\r\n\r\nGiven:\r\n\r\n>>> f = a_host.file_proxy(\"/foo.txt\")\r\n\r\nYou could upload and download from str using these two:\r\n\r\n>>> f.upload_from_str(\"Hi!\")\r\n>>> f.download_to_str()\r\n'Hi!'\r\n\r\nAnd using a filename like this:\r\n\r\n>>> f.upload_from_file(\"/etc/motd\")\r\n>>> f.download_to_file(\"/tmp/motd\")\r\n\r\nAnd lastly, using file-like objects:\r\n\r\n>>> f.upload(StringIO(\"Test!\"))\r\n>>> fp = StringIO()\r\n>>> f.download(fp)\r\n>>> fp.getvalue()\r\n'Test!'\r\n\r\nRenaming Files\r\n--------------\r\n\r\nRenaming is a method of the file proxies, called `rename`. It returns a new\r\nfile proxy for the renamed-to file, so the common pattern will be:\r\n\r\n>>> a_file = a_host.file_proxy(\"hello_world\")\r\n>>> a_file = a_file.rename(\"foobar\")\r\n\r\nThis will issue a rename command, too, so `a_file` will essentially be the same\r\nas before, with a new name and a new instance ID.\r\n\r\nDeleting Files\r\n--------------\r\n\r\nDeleting a file is much like renaming it: it's a method of the file proxies,\r\ncalled `delete`. It, however, doesn't have a meaningful return value.\r\n\r\n>>> a_file.delete()\r\n\r\nMirroring\r\n=========\r\n\r\n`ftptool` supports two types of mirroring: local to remote, and remote to\r\nlocal. As in, it can download a whole directory and all descendants into a\r\nlocal directory, for you to play with. It can also upload a whole directory to\r\na remote host.\r\n\r\nThe first one, downloading, is called `mirror_to_local`. It's used like so:\r\n\r\n>>> a_host.mirror_to_local('/a_dir', 'my_copy_of_a_dir')\r\n\r\nThe cousin, mirror_to_remote, has the same signature; source first, then\r\ndestination.\r\n\r\n>>> a_host.mirror_to_remote('my_copy_of_a_dir', '/a_dir')\r\n\r\nIf the local working directory is the one you want to upload, you can just give\r\n`mirror_to_remote` an empty string or a dot.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://blogg.se", "keywords": "", "license": "UNKNOWN", "maintainer": "", "maintainer_email": "", "name": "ftptool", "package_url": "https://pypi.org/project/ftptool/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/ftptool/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://blogg.se" }, "release_url": "https://pypi.org/project/ftptool/0.7.1/", "requires_dist": null, "requires_python": null, "summary": "Higher-level interface to ftplib", "version": "0.7.1" }, "last_serial": 1337116, "releases": { "0.4": [ { "comment_text": "", "digests": { "md5": "69470b5b7f42cefa2eabee5bd2975912", "sha256": "9d9eab189c2c8a49eab0a36204ae4c68bab1f225e5d171081f9875071e3aa94b" }, "downloads": -1, "filename": "ftptool-0.4.tar.gz", "has_sig": false, "md5_digest": "69470b5b7f42cefa2eabee5bd2975912", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9089, "upload_time": "2010-01-22T16:05:24", "url": "https://files.pythonhosted.org/packages/62/49/5e1bd60e81db40c8bdf62e7acaf5dadd533b5e3bf6af3523d5ece64b4e64/ftptool-0.4.tar.gz" } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "ef04616e96bba992815dcb56c40c30f0", "sha256": "1cf662d1c1d813ea6e97c9084a065e2a6308b420b4561b7f64b50c62c06de8ea" }, "downloads": -1, "filename": "ftptool-0.4.1.tar.gz", "has_sig": false, "md5_digest": "ef04616e96bba992815dcb56c40c30f0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9100, "upload_time": "2010-01-25T13:44:00", "url": "https://files.pythonhosted.org/packages/8d/a1/a307e6ee8fd86d1fc3ed82ce38420e4081b6f4ae46c5c7b253c447a53a1a/ftptool-0.4.1.tar.gz" } ], "0.4.2": [ { "comment_text": "", "digests": { "md5": "e92e71ff785f17fee799f2a000d9e7b8", "sha256": "184c0028c3d95abe7540265bf8d2dca08bf35b2b452df3256119a7cb81bb1ad7" }, "downloads": -1, "filename": "ftptool-0.4.2.tar.gz", "has_sig": false, "md5_digest": "e92e71ff785f17fee799f2a000d9e7b8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9648, "upload_time": "2010-01-25T13:50:04", "url": "https://files.pythonhosted.org/packages/21/24/0ac339f2e8efc780b92ccaf54c286bc094485db2e3b0ec5250fc8d395faf/ftptool-0.4.2.tar.gz" } ], "0.5": [ { "comment_text": "", "digests": { "md5": "d9fafbecd1e19ac5edc1be0de103f4ae", "sha256": "38353fd04e0065cc2a5cb11ec75074308e3aaefa9ed15f62537e3bb4bceab477" }, "downloads": -1, "filename": "ftptool-0.5.tar.gz", "has_sig": false, "md5_digest": "d9fafbecd1e19ac5edc1be0de103f4ae", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9732, "upload_time": "2010-02-19T11:21:14", "url": "https://files.pythonhosted.org/packages/fd/06/06498407fdbe0d3d52c6cb1cc40b9f874c6589d9c997347f2aeb35506678/ftptool-0.5.tar.gz" } ], "0.5.1": [ { "comment_text": "", "digests": { "md5": "ed8a048038d5907f8e5a3c946831f3d6", "sha256": "0b333d877d5bef820752f1657544f0e1284ed42387a0f4b60602e76d9ed5d139" }, "downloads": -1, "filename": "ftptool-0.5.1.tar.gz", "has_sig": false, "md5_digest": "ed8a048038d5907f8e5a3c946831f3d6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9906, "upload_time": "2010-02-19T14:39:14", "url": "https://files.pythonhosted.org/packages/76/b8/1a930e1b99286b9c76a44b9a0435357e8ff6a027e07490d32aa25c97fe81/ftptool-0.5.1.tar.gz" } ], "0.7.1": [ { "comment_text": "", "digests": { "md5": "2524f45138931737e44cefcecfb61dd8", "sha256": "d2f7d447fcc1654b3ad68d3786d6c8030775926a1ba1d90c1ad11959af4162a2" }, "downloads": -1, "filename": "ftptool-0.7.1.tar.gz", "has_sig": false, "md5_digest": "2524f45138931737e44cefcecfb61dd8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10381, "upload_time": "2014-12-09T14:16:52", "url": "https://files.pythonhosted.org/packages/30/c3/40449bf53ac7382bfd8db7af74686406699bddce4db1cff26d53e671fba2/ftptool-0.7.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "2524f45138931737e44cefcecfb61dd8", "sha256": "d2f7d447fcc1654b3ad68d3786d6c8030775926a1ba1d90c1ad11959af4162a2" }, "downloads": -1, "filename": "ftptool-0.7.1.tar.gz", "has_sig": false, "md5_digest": "2524f45138931737e44cefcecfb61dd8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10381, "upload_time": "2014-12-09T14:16:52", "url": "https://files.pythonhosted.org/packages/30/c3/40449bf53ac7382bfd8db7af74686406699bddce4db1cff26d53e671fba2/ftptool-0.7.1.tar.gz" } ] }