pwd() method of ftp class in Python

The pwd() method sends the FTP command PWD to a connected FTP server and returns the present working directory of the currently logged in user on the server.

Ftp Updated 9 Oct 2019 1 min read

Method Name

pwd

Method Signature

pwd()

Return Value

Returns the present working directory.

Method Overview

  • The method returns the present working directory on the FTP server for the currently logged in user.
  • The FTP command used is PWD.

Example

python
# Example python program to get the present working directory

# on the FTP server

from ftplib import FTP

# Connect to the FTP server

ftp = FTP(host="agreatftpserver.com");

print(ftp.getwelcome());

# Login to the FTP server

respMessage = ftp.login();

print(respMessage);

# Get the current working directory

respMessage = ftp.pwd();

print(respMessage);

Output

Output
220 (vsFTPd 3.0.3)

230 Login successful.

/