Found 10451 Articles for Python

How to copy a file to a remote server in Python using SCP or SSH?

Rajendra Dharmkar
Updated on 18-Feb-2020 07:10:47

16K+ Views

The easiest way to copy files from one server to another over ssh is to use the scp command. For calling scp you'd need the subprocess module. exampleimport subprocess p = subprocess.Popen(["scp", "my_file.txt", "username@server:path"]) sts = os.waitpid(p.pid, 0)You need the waitpid call to wait for the copying to complete.Another solution is to open a ssh connection and use the scp module.  examplefrom paramiko import SSHClient from scp import SCPClient ssh = SSHClient() ssh.load_system_host_keys() ssh.connect('user@server:path') with SCPClient(ssh.get_transport()) as scp:     scp.put('my_file.txt', 'my_file.txt') # Copy my_file.txt to the serverRead More

How to copy files from one server to another using Python?

Rajendra Dharmkar
Updated on 16-Dec-2019 07:53:53

8K+ Views

The easiest way to copy files from one server to another over ssh is to use the scp command. For calling scp you'd need the subprocess module.For exampleimport subprocess p = subprocess.Popen(["scp", "my_file.txt", "username@server:path"]) sts = os.waitpid(p.pid, 0)You need the waitpid call to wait for the copying to complete.Another solution is to open a ssh connection and use the scp module.For examplefrom paramiko import SSHClient from scp import SCPClient ssh = SSHClient() ssh.load_system_host_keys() ssh.connect('user@server:path') with SCPClient(ssh.get_transport()) as scp:     scp.put('my_file.txt', 'my_file.txt') # Copy my_file.txt to the serverRead More

How to get the maximum file name length limit using Python?

Niharikaa Aitam
Updated on 08-Jun-2025 12:56:40

2K+ Views

In Python, when performing file operations such as creating or renaming files, one of the limitations is the maximum length limit of a file name, and when we exceed this limit, then results in errors such as OSError: [Errno 36] File name too long. Using os.pathconf() function In Python, the os.pathconf() function is used to get system-specific configuration values related to files and directories. This function also helps in checking limits such as the maximum file name length or the maximum path length allowed by the file system. Syntax Following is the syntax of using the os.pathconf() function - os.pathconf(path, name) ... Read More

What is the maximum file size we can open using Python?

Niharikaa Aitam
Updated on 10-Jun-2025 17:34:51

3K+ Views

In Python, there is no fixed maximum file size that we can open. Python can open files of any size as long as the operating system and file system support until there is enough memory and disk space available. The limit of maximum file size comes with the system architecture, i.e., 32-bit, 64-bit, the file system, such as FAT32, NTFS, ext4, and how the file is processed in the code. System and File System Limits Following are the system and file system limits - FAT32 – Maximum file size: 4 GB NTFS (Windows) – Supports ... Read More

How to extract all the .txt files from a zip file using Python?

Niharikaa Aitam
Updated on 10-Jun-2025 18:29:03

2K+ Views

Python provides a built-in module called zipfile that allows us to create, read, write, and extract ZIP archives. When we want to extract only specific files, such as all .txt files, then we can perform filtering of the file names using string methods such as endswith(). A ZIP file is one of the archive formats which is used to compress one or more files into a single file to easily store and transfer data. It reduces the file size and keeps all related files compressed together for sharing over the internet and for saving disk space. Steps involved in ... Read More

How are files extracted from a tar file using Python?

Niharikaa Aitam
Updated on 28-May-2025 17:28:12

21K+ Views

A TAR file is abbreviated as Tape Archive, which is an archive format used mainly in Unix and Linux environments. The Tar file is used to collect more number of files into a single file, which makes it easier to share or backup together. In Python, when we want to work with TAR files, we can use the tarfile module, which allows us to create, read and extract TAR archives programmatically. In this article, we will explore how to extract the files from tar file by using Python. Extracting all files from a"tar" file The extractall() method in Python is ... Read More

How are files added to a zip file using Python?

SaiKrishna Tavva
Updated on 17-Mar-2025 16:58:53

3K+ Views

Managing files and archives is an essential skill. One common archive format is the ZIP file, which simplifies data compression and storage. Python, known for its versatility and power, provides the zip file module, making it easy for developers to interact with ZIP files efficiently. Key Features of the zipfile Module Some key features of the zipfile module are as follows- Creating ZIP files: You can create new ZIP archives. Modifying existing ZIP files: You can add files to existing archives. Reading ZIP files: You can extract ... Read More

How are files added to a tar file using Python?

Niharikaa Aitam
Updated on 27-May-2025 18:14:57

2K+ Views

Python offers a built-in module named tarfile, which allows developers to create, read, and modify tar archives, i.e., standard Unix tarballs. We can use this module to compress multiple files into a single archive, with or without compression. Different File Modes to Create a tar file Here are the available different file modes to create a tar file using Python - "w": Write a tar archive without compression. "w:gz": Write a gzip-compressed archive. "w:bz2": Write a bzip2-compressed archive. "w:xz": Write an xz-compressed archive (Python 3.3+). Adding a Single File to ... Read More

How to create a zip file using Python?

Sarika Singh
Updated on 28-May-2025 14:44:07

69K+ Views

ZIP is a widely used file format that compresses one or more files into a single archive file. This file format helps to reduce storage space and simplifies sharing or save backup of large data files. ZIP archives usually have a .zip file extension and are commonly used across different platforms. Compressed ZIP files reduce the size of the original directory by applying a compression algorithm. These result in faster file sharing over a network as the size of the ZIP file is significantly smaller than the original file. Creating ZIP files in Python In Python, we have the two ... Read More

How to create a tar file using Python?

Sarika Singh
Updated on 29-May-2025 03:23:40

14K+ Views

TAR stands for Tape Archive Files. The Tar files are the archive files which allows us to store numerous files in a single file. A Open-source software is distributed using tar files. Tar files typically end in .tar later they can be compressed using tools such as gzip which have the file ending as tar.gz. Different file modes to create a tar file Here are the available different file modes to create a tar file using Python ‐ "w": Write a tar archive without compression. "w:gz": Write a gzip-compressed archive. "w:bz2": Write a ... Read More

Advertisements