FTP-PYTHON is developed for pushing the files to the FTP servers based on time schedule. The program is developed in way once the file is pushed to the FTP server that perticular files will be moved to the local directory the local directory will store the files upto 30 days then it will cleared. It will also maintain the logs for updo 30 days to cross check the records or any issues you can see the logs in logs directory.
- Python3.6 or greather than Python3.6
Step1: Download or clone the library
sudo git clone https://github.com/Saleem344/FTP-PYTHON.git
Step2: Create virtual environment
Python3 -m venv venv
Step3: Activate virtual environment
source venv/bin/activate
Step4: Install requirements.txt
sudo pip install -r requirements.txt
step5: Change the credential in credential.py
file accourding to your requirement
Ex :
result['host'] = 'FTP-energy.systems'
result['username'] = 'Admin'
result['private_key'] = 'C:/Program Files/TEST_FTP/.ssh/privetkey.pem'
result['FTP_path'] ='/srv/data/FTP-users/Admin/powerdata/'
result['local_path'] = 'C:/FTP_DATA/'
result['local_move_path'] = 'C:/FTP_DATA/FTP_DATA_OLD/'
Step6: Change the timing in schedule for how many minutes you want to push the files
Ex:
schedule.every(1).minutes.do(ftp.data_push,'Test','writedaily')
Step6: To test run your program
python app.py
Step7 : Install app.py
as startup service.
Create Service
Step1: The file the file must have .service
extension under /lib/systemd/system/ directory
$ sudo vi /lib/systemd/system/test-py.service
Step2: Add some contant with python full path and description
[Unit]
Description=Test Service
After=multi-user.target
[email protected]
[Service]
Type=simple
ExecStart=/usr/bin/python /home/root/test_service.py
StandardInput=tty-force
[Install]
WantedBy=multi-user.target
Step3: Enable Newly Added Linux Service
Reload the systemctl daemon to read new file. You need to reload this deamon each time after making any changes in in .service file.
$ sudo systemctl daemon-reload
Step4: Now enable and start your new service
$ sudo systemctl enable test-py.service
$ sudo systemctl start test-py.service
Step5: Start/Restart/Status of Your New Service
For service status:
$ sudo systemctl status test-py.service
test-py.service - Test Service
Loaded: loaded (/lib/systemd/system/test-py.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2020-02-28 14:57:03 IST; 2s ago
Main PID: 32454 (python)
Tasks: 1 (limit: 4915)
CGroup: /system.slice/test-py.service
└─32454 /usr/bin/python /home/root/redis-key-expiry.py
Feb 28 14:57:03 websofttechs-MS-7C02 systemd[1]: Started Test Service.
Step6: Below commands to stop, start and restart your service manual.
$ sudo systemctl stop dummy.service
#To stop running service
$ sudo systemctl start dummy.service
#To start running service
$ sudo systemctl restart dummy.service
#To restart running service
Step1: Configure pm2
npm i -g pm2
Step2: Copy C:\Users\USER.pm2 to C:\etc.pm2
Step3. Set a new System Variable (not user level) name: PM2_HOME value: c:\etc.pm2
Step4: Runnning your app with pm2
run your pm2 app. ie: pm2 start app.py --name=FTP_PYTHON
.
Step5: pm2 save
to create a dump of the current apps running.
Step6: Testing app
Test everything is working, try: pm2 kill
and then pm2 resurrect
(app should be running, check with pm2 status should be online )
Step7: Run at startup
now we need to perform the resurrect command at startup, so:
npm install -g @innomizetech/pm2-windows-service
pm2-service-install -n PM2 --unattended
thats it.