FTP at Fabric - Mini Project - Requirements
There are few other attempts to create ftp connection using fabric. I've found most of them interesting. The most closest to my version can be found How I Deployed a PHP App via FTP using Fabric and Git
What Ftp libraries for python there are ?
Main thing that I'm interested in is support of netrc file - where I put credentials.
I've found examples that can be used for .netrc file with pycurl:
I know that using PyCurl can be a good option in this situation, but for now I'm dropping this solution.
FTP pre-solution
I didn't have enough time to make best source-code for this problem, so at least I've spend that time for investigation of solutions that are available.
But a quick-dirty solution - also called "duct taping" can be found below:
Simplest and the less-time consuming would be for now either use make ftp_upload
or a python-fabric-replicator that uses the same thing as in make:
def ftp_upload():
# simplest solution for now.
local('lftp ftp://{ftp_user}@{ftp_host} -e "mirror -R {deploy_path} {ftp_target_dir}; quit"'.format(**env))
To use this part of code at Fabric execution, use this command (uses .netrc password):
fab --set ftp_user=YOUR_FTP_USER,ftp_host=YOUR_FTP_HOST,ftp_target_dir=YOUR_FTP_TARGET_DIR ftp_upload
Examples above presents using ftp mirror
command.
I could use the mirror -R INPUT_DIR OUTPUT_TARGET_DIR; quit
with ftplib sendcmd
- But it's almost identical solution as with lftp command itself.
Code commits done for this post:
- Still to be revealed :) Upcomming github repository for this Mini-Project.
Tools and applications used:
-
Docker (local devserver showing pelican's post I'm currently working on)
-
Vi/VIM as my main editor
-
Tmux act as my session-protector - even if I close by mistake window with ssh to server on which I'm writing this post right now using tmux, tmux will hold session and I can reconnect to it next time and everything will be the same as before I've closed window with ssh
-
MobaXTerm for ssh connections.
LL (Lessons Learned)
1. FTPLib is not your best-friend.
As I've found out Python's FTPLib is just a simple connector to ftp with simplest accessing to ftp. No fancy-pancy like "put_directory" or other "put_directory_mirror_files" or something simillar.
I'm a little bit dissapointed - I had great hopes with this library.
Solution:
- Find better library or other libraries that are extended via this library - ftputil looks promissing
2. SFTP at the fabric source-code was a total surprice
When first I've found that there is a SFTP connector at the Fabric source-code - thought - THATS IT !
But yeah... wait a second... It's not using ftp.... hmm why not?
Right, I did forgot it's not FTP I thought - it's SSH based file transfer, not an FTP with some additional SSL/Security.
So I was back to root-cause-analysis - if I may use that medical terminology :) (Hope no medical stuff will be angry at me because of that :D )
Solution:
I will probably use the ftputil
library because it contains python-friendly naming convensions and extends ftplib much more than I could want for now.
Acknowledgements
Fabric usage for remote-create-dir via ftp on StackOverflow
Fabric for WP Engine site Deployments
Simple FTP Mirror - By Thimo Kraemer
What's next
1. Push source code of pelican and fabric deployment with fabric code that supports ftp using some library.
2. Add additional parameters to Fabric to be able to use different environments at the same time without having to change source-code of fabfile.py
See you at next Wednesday - this time I hope to make post faster then 1 hour before end of day :)
Comments
comments powered by Disqus