Ftp Automatic Login Server

Source: Internet
Author: User
Tags ftp access

Ftp Automatic Login Server

Let's look at shell programming. Next we will discuss how to automatically log on to the ftp server, so let's look at ftp.

I am using ubuntu

1. Make your computer an ftp server (executed by the root user)

Download and install vsftd: apt-get install vsftpd

After the installation is complete, use service vsftpd status to view the vstfpd service status

Modify the configuration file:/etc/vsftpd. conf

Listen = YES # server listener

Anonymous_enable = YES # Anonymous Access Allowed

# This statement indicates that the account can be used as anonymous and the password is empty for logon.

Local_enable = YES # allow access to the local host

# Shared directory
Local_root =/srv/ftp

Write_enable = YES # Write allowed

Chroot_local_user = YES

# Anon_upload_enable = YES
# Anonymous upload is allowed. The default value is NO, which can be enabled if it is troublesome. I am not responsible for any problems ~
# Anon_mkdir_write_enable = YES # Allow Anonymous Folder creation
Dirmessage_enable = YES # enter the folder to allow
Xferlog_enable = YES # ftp logging allowed
Connect_from_port_20 = YES # Port 20 is allowed as the data transmission Port
Secure_chroot_dir =/var/run/vsftpd/empty
Pam_service_name = vsftpd
Rsa_cert_file =/etc/ssl/private/vsftpd. pem

Meaning: http://www.sudu.cn/service/detail.php? Id = 11656

Set related directories

After installation, an ftp directory is added to/srv. At the same time, the system will add a user group named ftp. You can use ~ $ Sudo cat/etc/shadow view, such as ftp: *: 14993: 0: 99999: 7 :::. We create two directories named upload and download under the/srv/ftp directory for upload and download respectively. Next we will set permissions for the directories we just created, as shown below:


Permission/srv/ftp/upload/srv/ftp/download


User Group (ftp) read/write


Read/write by other users


Run the following command:


~ $ Sudo chmod 755/srv/ftp


~ $ Sudo chmod 777/srv/ftp/upload


~ $ Sudo chmod 755/srv/ftp/download


In this way, we allow the user group ftp access/srv/ftp (anonymous access), and grant the user group ftp write right to/srv/ftp/upload, therefore, users on the network can easily upload files, but note that after they upload files, only root has permissions for these files, that is, this directory can only be used for uploading, files in the directory cannot be downloaded. In addition, the user group is granted the ftp permission to read/home/ftp/download files, and the files copied to the directory are usually read to the user group, therefore, users on the network can only download files from this directory. This satisfies our pre-requirements.

Set User directory

If you have set anonymous users, you can log on to upload ~ This can save ~
(1) Add sudo groupadd ftpgroup

(2) Modify vsftpd. conf

~ $ Sudo gedit/etc/vsftpd. conf
Set the following three lines

# Restrict users to the home directory only

Chroot_local_user = YES
# Chroot_list_enable = YES
# (Default follows)
# Chroot_list_file =/etc/vsftpd/chroot_list
Change
Chroot_list_enable = YES
# (Default follows)
Chroot_list_file =/etc/vsftpd/chroot_list


(3) Add User ftpuser and set its directory to/srv/ftp/upload
Sudo useradd-g ftpgroup-d/srv/ftp-M ftpuser

(Note: G: the user's Group d: indicates that the location of the user's own directory is specified.

M: do not create a default home directory, that is, there is no own directory under/home)

(4) set the User Password passwd ftpuser
(5) edit the chroot_list file:
Sudo gedit/etc/vsftpd. chroot_list
The content is the ftp user name, and each user occupies one line, for example:
Ftpuser

(6) Restart vsftpd:
Sudo service vsftpd start

Reference http://blog.csdn.net/nation_chen/article/details/7066277

Note: ftp users cannot be deleted.

1. After the setting is successful, you can use the account in the local system to access ftp.

Verify upload, download, OK

2. There are various questions in the use process. When searching for answers, you can see the following command:

Adduser-g ftp-s/sbin/nologin mmc

Then I found that I could not log on to ftp. I don't know why.

Because we only want to learn how to log on to ftp automatically, now we can perform the next experiment, so we didn't go to the virtual user. If you are interested, you can take a look.

Iii. Instances

1. automatically upload and download files

 

#! /Usr/bin/keep CT-f # note that the beginning is/usr/bin/keep CT-f instead of/bin/bash, when writing habits, you will not pay attention to it # echo "Please input ip:" # read ip # echo "Please input filename: "# read filenameset ip [lindex $ argv 0] set filename [lindex $ argv 1] set savepath [lindex $ argv 2] spawn ftp $ ipexpect" Name * "# send a logon user" username "send" \ r "# login user Password login CT" password * "send" Password "send" \ r "Login CT" ftp> * "# specify the file path to be downloaded and the local file path "send" get $ filename $ s exists. Avepath "send" \ r "# The following prompt information is not displayed. I do not know why keep CT {" * Failed * "{send_user" Download failed \ r "; send "quit \ r"} "* Send *" {send_user "Download OK \ r"; send "quit \ r" }}# this can also be left empty. CT eof
You cannot use "." To execute this file. You need to set its attributes to executable,

 

The ultimate lab goal is:

1. Test ftp and download files

2. Understand the technical CT programming and automate the work

2. Automatic file backup

You must create a folder in the home directory with the permission of 777. You cannot upload the folder directly in the home directory. Otherwise, the error 553 cocould not create file is displayed.
/Srv/ftp # mkdir upload
/Srv/ftp # chmod 777 upload

 

#!/usr/bin/expect -fset ip [ lindex $argv 0 ]set filename [ lindex $argv 1]set backuppath [lindex $argv 2]spawn ftp $ipexpect "Name*"send "liyongchao"send "\r"expect "Password:*"send "liyongchao"send "\r"expect "ftp>*"send "put $filename $backuppath"send "\r"expect {        "*Failed*" {send_user "Backup failed!\r";send "quit\r"}        "*Transfer complete*" {send_user "Backup seccess\r";send "quit\r"}}

Note the line break "\ r"

 



 

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.