- How to use FTP by command-line in Ubuntu
- Install FTP on Ubuntu
- Configure The Firewall
- Configure the vsftpd Configuration File
- Test The FTP Server
- Connecting to FTP via the Linux command line
- 3 Answers 3
- How do I execute FTP commands on one line?
- 5 Answers 5
- ftp one line connection
- 1 Answer 1
- How to use FTP from the command-line on Linux
- Install FTP CLI
- Ubuntu
- Debian
- Arch Linux
- Fedora
- OpenSUSE
- Generic Linux
- Connect to FTP server over CLI
- Download FTP files over CLI
- Upload FTP files over CLI
How to use FTP by command-line in Ubuntu
We shall discuss installing the FTP server and will show you a few examples of how to upload and download single and multiple files on your Linux system.
F ile Transfer Protocol or FTP it is a protocol used to move files between computers. The FTP uses the client/server model. The server is always listening and waiting for FTP requests from other remote clients. When the server receives a request, it establishes a connection and handles the login.
During this tutorial, we are going to cover installing the FTP server and will show you some examples of how to upload and download single and multiple files.
Install FTP on Ubuntu
Before starting in the installation process of FTP, we need to ensure that the system is up-to-date using the following commands:
Next, let’s install the FTP server.
Step 1. Install the vsftpd package using the below command.
Install The vsftpd Package On Ubuntu
Step 2. Check the vsftpd status.
Check The vsftpd Service Status
As you can see from the above screenshot that the FTP server is active and running successfully.
Step 3. In case you need the vsftpd service to run automatically when the system starts up, you can use the command:
Now let’s move to the next section.
Configure The Firewall
After installing the required FTP server package, we need to perform some more configurations on the firewall.
Step 1. One of the basic configurations is adding a rule for the SSH, and this will prevent you from being locked out of by the server.
As you can, the output of the previous command will be something like the below screenshot:
Add A Rule For The SSH
Step 2. Now let’s open the 20 and 21 ports for FTP.
The output of the previous command should be something like the below screenshot:
Add Rule For Port 20
You may find the rule already added as the below output:
Add A Rule For Port 21
Step 3. Also lets open the ports for the passive FTP.
Add Rule For Passive FTP Port
Step 4. Now let’s enable the firewall if it is not already enabled.
Enable Firewall
To ensure that all of the previous rules have been added successfully, you can check the status of the firewall by running the below command:
Configure the vsftpd Configuration File
Some other few configurations needed to be done by editing the vsftpd configuration file which is found in “/etc/vsftpd.conf.”
Step 1. First and before editing the vsftpd configuration file, we need to take a backup from this configuration file.
Step 2. Open the vsftpd configuration file using your favorite editor; here we are going to use the vi editor.
Step 3. After opening the configuration file, you can search for the below settings, uncomment them and ensure that they have the right value.
There are a lot of settings in the vsftpd configuration file you can check them and decide which is best for you.
Step 4. After editing the vsftpd configuration file, save and quit it.
Step 5. Now we need to restart the vsftpd service to enable all the previous changes.
Test The FTP Server
To test the FTP server, you need to connect from another machine using the FTP client which is already installed on most of the Linux systems. In case the FTP client is not installed, you can install it using the command as follows:
Step 1. From the client machine, connect to the FTP server.
where the above IP is the FTP server machine IP.
Connect to Remote FTP Server
As you can see from the previous screenshot when you try to login to the FTP server, by default, it suggests the local user that you can use to login. After you enter the username and password, you will get the successful login message.
Step 2. Now let’s try out some commands, check your current directory.
Check Your Current Working Directory
As you can see from the previous output, the “/” here means the home directory of the local user logged in which in our case is “hendadel.”
List the content of the current directory.
Sample Output Of The ls Command
Step 3. From the FTP server machine, try to create a directory and create some files in it like the below screenshot.
Created a directory called ftpdir
Step 4. From the FTP client machine, move to the newly created directory and list its content to download it on the client machine.
Go to the ftpdir to download the listed files
Step 5. Now let’s download a single file.
Download Single File From The Remote FTP Server
As you can see from the previous screenshot, the file has been downloaded successfully. You can find the downloaded file in your client’s machine logged in user home directory like below.
Check The Downloaded File
Step 6. To download multiple files from the FTP server.
Download Multiple Files
And you can check the downloaded files as shown previously.
Check The Downloaded Files
Step 7. From the client FTP machine, while you are connected to the FTP server create a directory like the below screenshot.
Create Directory To Upload Files to FTP Server
Move from your current directory to the newly created directory.
From FTP Server Move to The uploaddir
Step 8. Now let’s upload one single file to the FTP server.
Upload One Single File To The FTP Server
Step 9. To upload multiple files to the FTP server.
Upload Multiple Files To The FTP Server
From the FTP server machine, you can check the uploaded files as below.
Check uploaded files
That ends this tutorial where we have installed the FTP server and used it to upload and download files. For any further assistance, please leave a comment and we will be glad to help you.
Источник
Connecting to FTP via the Linux command line
I need to upload files via FTP from the command line. I have this information: a URL, a username, a password, a port, and the fact that I am supposed to use passive mode.
How do I upload a file given this information?
Note that I am having to do this from a script, so I need to be able to enter this information automatically.
3 Answers 3
There’s many CLI (command line) clients out there. Most common is simply ftp . You’ve got ,
and «passive mode». Using ftp you should do:
-p switch means «use passive mode». Then you’ll be asked about your username and password. After successful login (server let you know about that), you are able to give some commands. Type help and press «enter» to get list of commands available. You can use e.g. cd , ls , mkdir ftp commands to change working directory (on the server), list its contents and create a new directory. If before running ftp you were in the same directory as you files you want to send, you can use put or mput command to start actual transfer. First command sends one file, second multiple files using globbing (e.g. mput *pdf will send all pdf files in current directory). To get simple help about command you can use help from within ftp app. I’d say that’s enough for starters. For the rest use man ftp or info ftp . To end ftp session type bye . There are other ways to do that but I think this one is just elegant :).
As for the other clients, some interesting choices were pointed here, but I personally use lftp . It’s just solid, good, flexible and easy to use ftp client. If you prefer more visual approach while still being under command line, you can go for mc or «Midnight Command». It’s general application file manager utilizing Norton Commander paradigm, but can be also used to access ftp servers.
Источник
How do I execute FTP commands on one line?
This is what I’m doing when I log into a FTP:
I’d like to do a one-line FTP command.
Something similar. as part of a script I’m trying to create. Nothing is getting transferred, I just need to echo some instructions and this is the easiest way I’ve found to do it between two of my systems.
$ ftp ftp> echo «hi» ?Invalid command ftp>
5 Answers 5
That really is more of a job for SSH (as others have pointed out), but if you’re determined to use ftp, try lftp. It’s freely available for all currently supported versions of Ubuntu. You can install it with the command sudo apt install lftp
lftp documents a -c switch that runs the command and then quits, but it appears to be broken in most distributions. -e will keep you connected unless you issue a quit .
/.netrc and make sure sure that’s mode 0600 . FTP can negotiate non-plain-text passwords on the wire.
I found this thread when I was searching for a way to have a single ftp command execute a file transfer from this machine to the ftp server. Here is how:
Create a file with the ftp commands in it: (call it ‘ftpcommands.txt’)
Then run the ftp command and feed the file into it:
The -n option keeps ftp from trying to log in automatically when it receives you ‘open’ command.
Hope THAT helps someone. I couldn’t find anything online that was this solution, so I had to figure it out myself.
Источник
ftp one line connection
I’m trying to connect to my Filezilla server (ms windows host) from command line under Debian 8.
I searched for documentation and saw plenty of tutorials saying that a good way to connect to a server in one line with credentials is:
ftp -in ftp://myusername:mypasswd@ip.v4.addr.here
When I run this command, ftp do not connect and I get the following error:
ftp: ftp://myusername:mypasswd@ip.v4.addr.here: Name or service not known
Does anybody know what’s wrong here ? Do I have to specify any port or something ? (the server is listening on port 21)
My goal is to write a short bash script that would upload a specific file. I only miss the connection part :\
1 Answer 1
I used to write ftp script all of the time! Very old school. As misled by others here, FTP is designed to work as a batch script and just because it’s archaic doesn’t mean it doesn’t work. Ftp and vsftp is highly insecure because your id/password is sent clear text over the network. This is why people us sftp or scp (which uses the SSH protocol). But, if clear text passwords over a network is not a concern for your environment, e.g. it’s a closed network, ftp is a valid option and a bit easier to set up and maintain than services using ssh.
This is an example script below:
#!/bin/bash ftp -nv myservernameorip
Just replace ‘myservernameorip’, ‘myuserid’ and ‘mypasswd’ with the real host name / IP, and account information; as well as change the ls , put and/or get command ‘some_files’ with real file paths.
Источник
How to use FTP from the command-line on Linux
Apr 11, 2019
Comment
Working with FTP from the command-line might sound trivial, as there are a lot of excellent FTP clients on Linux that provide a GUI to work with. Still, many users of the File Transfer Protocol use it over SSH and servers so that a GUI app won’t work.
There are a few useful command-line FTP clients on Linux. In fact, in the past, I talked about one great command-line app in my list of the best FTP clients for Linux. That said, in this post, we will not be focusing on that app, as it’s much too complicated for what we need it for; basic upload and download. Instead, we will use the standard GNU FTP client.
Note: the GNU FTP client will not work with SFTP or FTPS. It can only connect to FTP servers.
Install FTP CLI
The GNU FTP app is widely used, so, this package may already be pre-installed on quite a few distributions. That said, not every single distribution has the client pre-installed, so it’s a good idea to go over how to get it working before going over how to use it.
To install the FTP app on your Linux operating system, open up a terminal window by pressing the Ctrl + Alt + T or Ctrl + Shift + T keyboard combination. From there, follow the detailed instructions that correspond with the OS you are currently using.
Ubuntu
On Ubuntu Linux, the CLI FTP client is available in the “Ubuntu Main” software repository. To install it on your system, you must use the Apt terminal command.
Debian
The CLI FTP client has supported Debian Linux for a very long time. As a result, it’s easily installable via the “Debian Main” software repository.
To install the CLI FTP app on your Debian PC, use the Apt-get command below.
Arch Linux
Arch Linux users won’t be able to search the package repositories for an “FTP” package if they want to use this app, as the developers do not package the CLI FTP app separately. Instead, to use FTP from the command-line on Arch Linux, you must install the “inetutils” package with Pacman.
Fedora
The command-line FTP client is available to Fedora Linux users through the “Fedora x86_64” and “Fedora i386” software repositories. If you’re a Fedora user, install the package with the following Dnf command in a terminal window.
OpenSUSE
OpenSUSE users looking to use the CLI FTP client on their operating system will be happy to know that the program is installable on Leap 15.0, Leap 42.3 and Tumbleweed via the “OpenSUSE Oss All” software repository.
To start the installation on your SUSE system, launch a terminal window and use the Zypper command below.
Generic Linux
The standard command-line FTP client used on Linux that we will be covering in this article is part of the GNU Project. For this reason, it’s very easy to track down this app for all Linux operating systems out there.
To install the CLI FTP client on your Linux operating system, open up a terminal. Then, search for and install “ftp” or “inetutils”. Alternatively, if you can’t find the app anywhere in software sources, check out how to grab the source code from GNU.org.
Connect to FTP server over CLI
To start a new connection with your server in the FTP CLI application, go to the terminal and use the ftp command along with the IP address of the remote server.
Note: can’t figure out the remote IP address of your FTP server. Check out our guide about how to find out an IP address on Linux.
Assuming the address is successful, the FTP app will prompt the user to enter a username and password. Write in your server’s username and password, and you’ll gain access over CLI to the FTP server.
Download FTP files over CLI
Downloading files over FTP in the command-line is done with the get command. To start a download, try out the following command syntax.
Let the FTP client download the file(s) to your system. When successful, they’ll appear in the directory the terminal on your Linux PC started in (usually /home/username/).
Upload FTP files over CLI
Uploading files with the FTP command-line application uses the send command. To send a file or folder to a remote server, follow the command syntax below.
Sending files over FTP will take a few minutes. When the process is done, you’ll see it in the default upload directory on the remote server.
Источник