6

How to create ftp in google cloud compute engine? I can connect via SFTP without any issues, but my company is using a software to connect via FTP to download a XML file from the server. Unfortunately that software doesn't have SFTP connection facilities.

I saw lots of examples from the internet and to connect via SFTP not FTP.

Any idea's or tutorials ?

2 Answers 2

13

I found a way to do this, Please advice is there any risks.

apt-get install vsftpd libpam-pwdfile

nano /etc/vsftpd.conf

And inside the vsftpd.conf config file.

    # vim /etc/vsftpd.conf

    listen=YES
    listen_ipv6=NO
    anonymous_enable=NO
    local_enable=YES
    write_enable=YES
    local_umask=022
    nopriv_user=vsftpd
    chroot_local_user=YES
    allow_writeable_chroot=yes
    guest_username=vsftpd
    virtual_use_local_privs=YES
    guest_enable=YES
    user_sub_token=$USER
    local_root=/var/www/$USER
    hide_ids=YES

    listen_address=0.0.0.0
    pasv_min_port=12000
    pasv_max_port=12100
    pasv_address=888.888.888.888 # My server IP
    listen_port=211

Remove everything from the file and add these lines instead

auth required pam_pwdfile.so pwdfile /etc/ftpd.passwd

account required pam_permit.so

Create the main user that will be used by the virtual users to authenticate:

useradd --home /home/vsftpd --gid nogroup -m --shell /bin/false vsftpd

Once that is done we can create our users/passwords file.

htpasswd -cd /etc/ftpd.passwd helloftp

Next, add the directories for the users since vsftpd will not create them automatically.

mkdir /var/www/helloproject

chown vsftpd:nogroup /var/www/helloproject

chmod +w /var/www/helloproject

Finally, start the vsftp daemon and set it to automatically start on system boot.

systemctl start vsftpd && systemctl enable vsftpd

Check the status to make sure the service is started:

systemctl status vsftpd

    ● vsftpd.service - vsftpd FTP server
    Loaded: loaded (/lib/systemd/system/vsftpd.service; enabled)
    Active: active (running) since Sat 2016-12-03 11:07:30 CST; 23min ago
    Main PID: 5316 (vsftpd)
    CGroup: /system.slice/vsftpd.service
    ├─5316 /usr/sbin/vsftpd /etc/vsftpd.conf
    ├─5455 /usr/sbin/vsftpd /etc/vsftpd.conf
    └─5457 /usr/sbin/vsftpd /etc/vsftpd.conf

Finally add firewall rules to access via cloud.

Google Cloud Firewall Settings

enter image description here

enter image description here

Later I have changed my IP from 0.0.0.0 for more restriction

2
  • 2
    It work's fine for me, but with some changes: sudo nano /etc/pam.d/vsftpd // replace everything with this: auth required pam_pwdfile.so pwdfile /etc/ftpd.passwd account required pam_permit.so // end Commented Jan 4, 2020 at 10:26
  • 1
    "pasv_address=<external_instance_ip>" setting is mandatory to make it work from remote connections. Thank You! Commented Sep 18, 2022 at 18:16
2

Yes, It is possible to host an FTP server on Google Cloud. In fact, I wrote an in-depth blog about How to set up an FTP server on Google Cloud.

If your VM is base on Linux then you have to use an application like vsftpd to set up an FTP server.

Here are the steps:

Step 1: Deploy a Virtual Instance on Google Cloud
Step 2: Open SSH terminal
Step 3: Installing VSFTPD
Step 4: Create a User
Step 5: Configure vsftpd.conf file
Step 6: Preparing an FTP Directory
Step 7: FTP/S or FTP over SSL setup (optional)
Step 8: Opening Ports in Google Cloud Firewall
Step 9: Test and Connect

Not the answer you're looking for? Browse other questions tagged or ask your own question.