Transfering files with FTP via Command-Line

 

The FTP command (available in any Linux distribution and Windows) is an useful tool that allows you to transfer files into a FTP server without using third-party clients, the main issue is that you may need some guidance in order to properly use it. Here is what you need to know:

If the FTP command is not available for you on Linux, you may have to install it

  • Ubuntu: apt-get install ftp
  • CentOS: yum install ftp

Open a terminal (or a command prompt on Windows) and execute the following command:

ftp myftpserver.domain

Once the connection is established, the server will ask (at least it should) for your credentials like this:

220 ProFTPD 1.3.4a Server (Debian) [66.150.56.135]
Name (myftpserver.domain):

At this point, we should provide the username and password in order to access the server, just like this:

220 ProFTPD 1.3.4a Server (Debian) [66.150.56.135]
Name (myftpserver.domain): cumanzor3
331 Password required for cumanzor3
Password:
230 User cumanzor3 logged in
Remote system type is UNIX.
Using binary mode to transfer files.

Now, we should be able to start a file transference from our computer or do some file retrieval. The FTP session that you have started will behave like a unix terminal, in short you can use not just the file transfer commands but also perform a file/directory manipulation as well .

Here is an example of some ftp commands that you can use:

  1. cd: the classic change directory
  2. ls: list directory contents
  3. chmod: change directory/file permissions (it could be blocked by system admins)
  4. delete: deletes a file on remote system
  5. rmdir: deletes a directory on remote system
  6. get: Downloads a single file
  7. mget: downloads multiples file (wildcard allowed)
  8. put: Uploads a single file to ftp server
  9. mput: Uploads multiple files to ftp server
  10. quit: Closes the FTP Connection

Let’s do some FTP action

When you start a FTP session you have to take in consideration two key terms: local directory and remote directory. Local directory is basically the folder on your computer on which files are going to be downloaded or the folder that contains the files that can be uploaded (not mandatory). The remote directory is the path in the FTP SERVER on which you are going to upload files (or get files), the path is usually set by default upon server configuration (admin stuff).

Now take a look at this scenario, I want to “upload” a video file into my ftp server, my file is located at /home/user/videos and I want to upload it into a remote folder called /media/avi.

[email protected]:~$ cd /home/user/videos
[email protected]:~/home/user/videos$ ls
movie.avi
[email protected]:~/home/user/videos$ ftp anotherServer.com
Connected to anotherServer.com.
220 ProFTPD 1.3.4a Server (Debian) [66.150.56.135]
Name (anotherServer.user): cumanzor3
331 Password required for cumanzor3
Password:
230 User cumanzor3 logged in
Remote system type is UNIX.
Using binary mode to transfer files.

 

ftp> cd /media
250 CWD command successful
ftp> pwd
257 "/media" is the current directory
ftp> cd avi
250 CWD command successful
ftp> pwd
257 "/media/avi" is the current directory
ftp> put movie.avi
local: movie.avi remote: movie.avi
200 PORT command successful
150 Opening BINARY mode data connection for movie.avi
226 Transfer complete
734944554 bytes sent in 40.59 secs (17683.7 kB/s)
ftp> quit
221 Goodbye.

Take a look at each line, we did start the ftp session directly at the /home/user/videos folder, that’s our local directory, once the connection is set, I did navigate remotely into the /media/avi folder, then with the PUT command, I did upload my video into the ftp server, finally I did close the session with the quit command.

If we want to retrieve instead of upload, we should use the GET command, the procedure is the technically the same.

[email protected]:~$ cd /home/user/videos
[email protected]:~/home/user/videos$ ftp anotherServer.com
Connected to anotherServer.com.
220 ProFTPD 1.3.4a Server (Debian) [66.150.56.135]
Name (anotherServer.user): cumanzor3
331 Password required for cumanzor3
Password:
230 User cumanzor3 logged in
Remote system type is UNIX.
Using binary mode to transfer files.

ftp> cd /media
250 CWD command successful
ftp> pwd
257 “/media” is the current directory
ftp> cd avi
250 CWD command successful
ftp> pwd
257 “/media/avi” is the current directory
ftp> get movie.avi
local: movie.avi remote: movie.avi
200 PORT command successful
150 Opening BINARY mode data connection for movie.avi
226 Transfer complete
734944554 bytes received in 40.59 secs (17683.7 kB/s)
ftp> quit
221 Goodbye.

[email protected]:~/home/user/videos$ ls
movie.avi

As you can see, these examples were just some basic operations that we can do with the FTP command, if you want learn more about this, please take a look at the FTP Man page

Follow me

Carlos Alberto Umanzor Arguedas

Web Developer at carlosumanzor.com
Web Developer, QA Engineer and Gamer Enthusiast, Developer of Linkcrawler and Father of a future computer ninja.
Follow me

 

Pin It on Pinterest

Shares
Share This
Optimization WordPress Plugins & Solutions by W3 EDGE