getwelcome() method of FTP class in Python

The getwelcome() method, returns the welcome message sent by the FTP server on successfully connecting to it. The string returned is the same one returned upon a successful call to the connect() method.

Ftp Updated 27 Sep 2019 1 min read

Method Name

getwelcome

Method Signature

getwelcome()

Return Value

A Python string containing the welcome message sent by the FTP server.

Parameters

None.

Overview

  • When the connection is established with the FTP server, a 220 message is sent to the client. This message could be long containing greetings, welcome message or policies that are to be adhered.
  • The getwelcome() method returns this message. The same message is returned by the connect() method as well.

Example

python
from ftplib import FTP

hostName = "publicftpserverthatallowstesting.com";

# Create an FTP instance

ftpObject = FTP("");

ftpResponse = ftpObject.connect("hostName");

ftpResponse = ftpObject.login(user="demo", passwd="password");

# Get the welcome message from server

welcomeMessage = ftpObject.getwelcome();

# This message is the same as the value of the ftpResponse variable

# after the connect method

print(welcomeMessage);

Output

Output
220 Connection successful to the hypothetical  publicftpserverthatallowstesting.com. Welcome!