The Size() Method Of FTP Class In Python

Method Name:


Method Signature:



filename:Name of the file

Return Value:

  • Upon success, returns the file size in number of bytes.
  • Upon failure, it returns None.


  • The method size(), returns the size of the file in number of bytes.
  • The size() method, internally sends the FTP command SIZE appended by a space and the filename.
  • Upon success, the server sends back a 213 message, with the size of the file in number of bytes, which is parsed and returned by the size() method.
  • The size() method works for files; it does not work for directories.


# Example Python Program to get the size of a file in the FTP server

from ftplib import FTP


# Connect to the host

ftp = FTP(host="");



# Login to the FTP server

loginRepsonse = ftp.login();



# Get the size of a file

fileName = "";

size = ftp.size(fileName);

print("Size of the file %s is %s bytes"%(fileName, size));



220 (vsFTPd 3.0.3)

230 Login successful.

Size of the file is 1024 bytes

Copyright 2024 ©