How to Transfer a Directory to a Remote Server Using FTP in Linux: Complete Step-by-Step Guide


4 views

When working with Linux systems, transferring files and directories between local and remote servers is a fundamental task. FTP (File Transfer Protocol) remains one of the most common methods for this operation, especially when dealing with web server deployments.

First, establish a connection to your remote server using the FTP client:

ftp your_server_ip
# Example:
ftp 10230.35.211

You'll be prompted to enter your username and password. Ensure you have the proper permissions to access both the local directory and the remote destination.

After successful login, navigate to the target directory on the remote server:

ftp> cd /www/html

Verify your current remote directory with:

ftp> pwd

For transferring directories, you have several options:

Method 1: Using mput with Wildcards

ftp> lcd /home/qa/html/dataTable-1.6
ftp> mput *

This will upload all files in the current local directory. However, it won't preserve the directory structure.

Method 2: Using tar for Directory Preservation

A more robust approach for maintaining directory structures:

# On local machine:
tar czf dataTable-1.6.tar.gz /home/qa/html/dataTable-1.6

# In FTP session:
ftp> put dataTable-1.6.tar.gz

# On remote server after transfer:
tar xzf dataTable-1.6.tar.gz -C /www/html

For frequent transfers, consider using a script:

#!/bin/bash
HOST='10230.35.211'
USER='your_username'
PASS='your_password'
FOLDER='/home/qa/html/dataTable-1.6'
TARGET='/www/html'

ftp -n $HOST <

For more advanced file transfers, consider these alternatives:

  • scp: Secure copy over SSH
  • rsync: Efficient file synchronization
  • sftp: Secure FTP over SSH

If you encounter permission issues:

chmod -R 755 /home/qa/html/dataTable-1.6

For connection problems, verify your FTP server is running and firewall settings allow FTP traffic (typically port 21).


When working with Linux servers, transferring entire directories via FTP is a common task for web developers deploying code or updating content. In this case, we're moving the "dataTable-1.6" folder from a local machine to the server's web directory.

Before initiating the transfer, ensure:

  • You have proper FTP credentials (username/password)
  • The remote directory (/www/html) exists and is writable
  • Your local path (/home/qa/html/dataTable-1.6) is accessible

Here's the proper sequence of commands for directory transfer:

ftp 10230.35.211
> Enter username and password when prompted
ftp> cd /www/html
ftp> lcd /home/qa/html
ftp> mkdir dataTable-1.6
ftp> cd dataTable-1.6
ftp> lcd dataTable-1.6
ftp> mput *

Some FTP clients support recursive directory transfers. In command-line FTP, you might need to:

ftp> prompt
ftp> mput *

The prompt command toggles interactive prompting off for multiple file transfers.

For easier directory transfers, consider these alternatives:

  • SFTP: More secure option with similar commands
  • rsync: Better for large directories
  • Graphical clients like FileZilla for drag-and-drop transfers

If you encounter problems:

  • Check directory permissions (755 for directories, 644 for files)
  • Verify the FTP server allows uploads
  • Ensure sufficient disk space on the server
  • Try the binary command before transfer to prevent corruption

Here's what a successful transfer might look like:

qa@qadesktop2:~$ ftp 10230.35.211
Connected to 10230.35.211.
220 FTP Server Ready
Name (10230.35.211:qa): yourusername
331 Password required
Password: [hidden]
230 User logged in
Remote system type is UNIX.
ftp> cd /www/html
250 CWD command successful
ftp> lcd /home/qa/html
Local directory now /home/qa/html
ftp> mkdir dataTable-1.6
257 "/www/html/dataTable-1.6" created
ftp> cd dataTable-1.6
250 CWD command successful
ftp> lcd dataTable-1.6
Local directory now /home/qa/html/dataTable-1.6
ftp> binary
200 Type set to I
ftp> mput *
mput file1.js? y
200 PORT command successful
150 Opening BINARY mode data connection
226 Transfer complete
mput file2.css? y
[...]
ftp> quit
221 Goodbye