Storlines Method Of Ftp Class In Python

Method Name:


Method Signature:

storlines(cmd, fp, callback=None)

Return value:

Response message from the FTP server of type str .


  • The storlines() method copies a file(uploads) from an FTP client or another FTP server to the destination FTP server.
  • As storlines() operates on ASCII mode, it should not be used to transfer binary files. The ASCII mode filer transfer in FTP does automatic translation of CR LF characters in the ASCII stream based on the destination file system.
  • For transferring a binary file using FTP, the method storbinary() can be used. No translation of CR LF happens while transferring a file in binary mode.


# Example python program to upload a file in ASCII mode

from ftplib import FTP


fileName    = "./ToServer.txt";


# Open in binary mode else Python will return Unicode strings

fileObject  = open(fileName, 'rb');


# Create an ftp instance

ftpObject = FTP();


# Connect to the FTP server

ftpResponse = ftpObject.connect(host="");



# Login to the FTP server

ftpResponse = ftpObject.login();



# Change the working directory

ftpResponse = ftpObject.cwd("/upload");



# Send the text file to the FTP server

storeCommand    = "STOR %s"%fileName;

ftpResponse = ftpObject.storlines(storeCommand, fileObject);




220 (vsFTPd 3.0.3)

230 Login successful.

250 Directory successfully changed.

226 Transfer complete.


Copyright 2024 ©