Skip to main content

Easy usage of FTP operation

Project description

NOTE: THIS PACKAGE IS IN TEST VERSION YET.

EasyFTP

enter image description here

EasyFTP is a Python library that simplifies the process of interacting with FTP (File Transfer Protocol) servers. With EasyFTP, you can easily upload, download, delete, and list files and directories on remote FTP servers using a simple and intuitive interface.

Features

  • Connect to FTP servers with ease.
  • Upload files and directories to remote servers.
  • Download files and directories from remote servers.
  • Delete files and directories on remote servers.
  • List files and directories on remote servers.
  • (not implemented) Support for both FTP and secure FTP (FTPS).

Installation

You can install EasyFTP via pip:

pip install EasyFtp

Usage

Structure of the directory /example used here :

/examples
├── dir1
│   ├── a.png
│   ├── b.png
│   └── c.jpg
├── dir2
│   └── subdir-a
│       ├── random.key
│       └── randon.key
├── dir3
│   ├── some.binary
│   └── some.binary.X
├── example.py
└── example.py2
  • Establishing connection
from EasyFTP import EasyFTP 

with EasyFTP() as session:
	session.connect("192.168.1.1", 21, "admin", "12345678", timeout = 30)
	# Change it to your option, and timeout is not necessary.
  • Listing files on remote directory
from EasyFTP import EasyFTP 

with EasyFTP() as session:
	session.connect("192.168.1.1", 21, "admin", "12345678", timeout = 30)
	# Change it to your option, and timeout is not necessary.
	l = session.ls("/examples")
	# Directory argument is not necessary;
	# It will print structure of current directory when there is no argument.
	print(l)

It will print, for example: ["dir1", "dir2", "dir3", "example.py", "example.py2"]

  • Changing directory in remote (and printing current working directory)
from EasyFTP import EasyFTP

with EasyFTP() as session:
	session.connect("192.168.1.1", 21, "admin", "12345678", timeout = 30)
	# Change it to your option, and timeout is not necessary.
	
	session.cd("/examples")
	# This will change your directory to /examples.
	# NOTE: Relative path is not tested yet.

	print(session.cd())
	# This will print "/examples", which is your current working directory.
	# It does this when there is no argument passed to it.

	print(session.pwd())
	# It works like session.cd().
  • Downloading specific file(s) from remote
from EasyFTP import EasyFTP 

with EasyFTP() as session:
	session.connect("192.168.1.1", 21, "admin", "12345678", timeout = 30)
	# Change it to your option, and timeout is not necessary.

	# Low-level example.
	# This works by reading file on remote and retrieve it as string,
	# and then write it to your desired file manually.
	# This will raise FTPError if you don't have permission to
	# read files, write permission to your local file,
	# or error(s) not described here. It can be anything.
	content = session.read("/examples/example.py")
	with open("./example.py", encoding = "utf-8") as f:
		f.write(content)

	# This will change your directory to /examples.
	# So you won't need to specify path to file IF IT EXISTS IN THE PATH.
	# NOTE: Relative path is not tested yet.
	session.cd("/examples")

	# High-level example.
	# This works by reading file on remote and retrieve it as file,
	# which will be saved to specified file(s)/path which local_path variable indicates.
	# This can raise error, too. Read them carefully if it happened.
	# TODO : Return whether or not it has succeeded.

	# Downloading one file.
	session.download("example.py", "example.py")

	# TODO : Downloading multiple files using wildcard(s).
	# session.download("ex*.py*", ".")

	# Downloading a directory.
	# local_file MUST indicate a directory to do this.
	# The subdirectory(subdirectories) in the directory will be downloaded too.
	# TODO : Add filter object to filter files to be downloaded.
	session.download("dir2", ".")
  • Uploading file to remote
from EasyFTP import EasyFTP 

with EasyFTP() as session:
	session.connect("192.168.1.1", 21, "admin", "12345678", timeout = 30)
	# Change it to your option, and timeout is not necessary.

	# Low-level example.
	# This works by converting encoded string it as BytesIO,
	# and then write it to your desired remote file manually.
	# This will raise FTPError if you don't have permission to
	# read files, write permission to your local/remote file,
	# or error(s) not described here. It can be anything.
	session.write("/example/example.py3", "print('hello world!')")

	# This will change your directory to /examples.
	# So you won't need to specify path to file IF IT EXISTS IN THE PATH.
	# NOTE: Relative path is not tested yet.
	session.cd("/examples")

	# High-level example.
	# This works by reading file on local and retrieve it as binary,
	# which will be saved to specified file(s)/path which remote_path variable indicates.
	# This can raise error, too. Read them carefully if it happened.
	# TODO : Return whether or not it has succeeded.

	# Uploading one file.
	session.upload("example.py4", "example.py4")

	# TODO : Uploading multiple files using wildcard(s).
	# session.download("ex*.py*", ".")

	# Uploading a directory.
	# remote_file MUST indicate a directory to do this.
	# The subdirectory(subdirectories) in the directory will be uploaded too.
	# TODO : Add filter object to filter files to be uploaded.
	session.download("./new_dir", ".")
  • Deleting file from remote
from EasyFTP import EasyFTP 

with EasyFTP() as session:
	session.connect("192.168.1.1", 21, "admin", "12345678", timeout = 30)
	# Change it to your option, and timeout is not necessary.

	# This will remove example.py from current directory,
	# But this will raise error because there is no file named
	# example.py in the root directory, it is in /example.
	# So be careful, there are always mistakes and errors.
	session.delete("example.py")

	# If you want to delete multiple files at once, please refer to EasyFTP.Filter module guide.
  • Renaming a file
from EasyFTP import EasyFTP 

with EasyFTP() as session:
	session.connect("192.168.1.1", 21, "admin", "12345678", timeout = 30)
	# Change it to your option, and timeout is not necessary.

	# This will change your directory to /examples.
	# So you won't need to specify path to file IF IT EXISTS IN THE PATH.
	# NOTE: Relative path is not tested yet.
	session.cd("/examples")

	# This will rename "example.py2" to "example.py".
	# If you are not sure about using this function or
	# you are used to linux systems, you can use EasyFTP.mv().
	# Both functions can move/rename directories, too.
	session.rename("example.py2", "example.py") # session.mv("example.py", "example.py2")
	
  • Making directory
from EasyFTP import EasyFTP 

with EasyFTP() as session:
	session.connect("192.168.1.1", 21, "admin", "12345678", timeout = 30)
	# Change it to your option, and timeout is not necessary.
	
	# This will create directory on /examples .
	session.mkdir("/examples/new_dir2")

	# This will change your directory to /examples.
	# NOTE: Relative path is not tested yet.
	session.cd("/examples")

	# This will create directory on your current directory.
	session.mkdir("/examples/new_dir3")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

EasyFTP-0.0.18b0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

EasyFTP-0.0.18b0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file EasyFTP-0.0.18b0.tar.gz.

File metadata

  • Download URL: EasyFTP-0.0.18b0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.1

File hashes

Hashes for EasyFTP-0.0.18b0.tar.gz
Algorithm Hash digest
SHA256 395571cea7e0e6f50614ea36c79a9c0bcfec1d0712e5ab75c061e4cff1f57057
MD5 11b4bb8bdd3f6c9fb8b2e27941843bbf
BLAKE2b-256 fb9b17c5e7fe64fbf67325e97a6b4fdd4caf2f072f92927311403850543b32d3

See more details on using hashes here.

File details

Details for the file EasyFTP-0.0.18b0-py3-none-any.whl.

File metadata

  • Download URL: EasyFTP-0.0.18b0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.1

File hashes

Hashes for EasyFTP-0.0.18b0-py3-none-any.whl
Algorithm Hash digest
SHA256 f9ded91cc67807d3cb3693d3bc48ff6d1c68421e38f00c0cf0fffc7650bca488
MD5 87dbb1371fe9cc3347faef61c136c670
BLAKE2b-256 6daba5173956349e5a2265797bd86467694e79d3a711d0e7d4bdea6fb0959aba

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page