ftp/ssh/shell/filezilla Flashcards
ftp: to log into ftp connection using python, type
import ftplib
ftp = ftplib.FTP(‘ftp.example.com’,’usename@example.com’,’password’)
ftp: To check the type of server
go to the site in chrome, open the network tab, and in the response header it will say
ftp: If you want to check the operating system you can use
http://toolbar.netcraft.com/site_report/
ssh: SSH allows
remote shell access and as slow encrypted file transfer
ssh: many hosting providers do not provide ssh access because
there have been cases of users of a shared server accessing each others files
ftp: ftp is mainly used for
making files publicly available through a browser, or transfering files to and from a server
ssh: ssh stands for
secured shell
ftp: ftp cannot
run shell commands
ftp: To upload an entire directory recursively, type
import ftplib
import os
ftp = ftplib.FTP(‘ftp.example.com’,’usename@example.com’,’password’)
my_file_path = r’/users/path/’
def upload_this(path):
files = os.listdir(path)
os.chdir(path)
for f in files:
if os.path.isfile(path + r’/{}’.format(f)):
fh = open(f, ‘rb’)
ftp.storbinary(‘STOR %s’ % f, fh)
fh.close()
elif os.path.isdir(path + r’/{}’.format(f)):
ftp.mkd(f)
ftp.cwd(f)
upload_this(path + r’/{}’.format(f))
ftp.cwd(‘..’)
os.chdir(‘..’)
upload_this(my_file_path)
ftp: To return your current directory, type
ftp.pwd()
ssh: To end an ssh connection, type
return
return
~.
note: returns are necessary
pythonanywhere: To ssh into pythonanywhere, type
ssh username@ssh.pythonanywhere.com
ssh: To copy a local file into a server through ssh, type
scp /path/file.py username@host.com:/path/folder
ssh: To copy a local file into pythonanywhere through ssh, type
scp ssh.py bigintro@ssh.pythonanywhere.com:/home/bigintro
ssh: To copy a file from a remote server to local, type
scp username@host.com:/path/folder /path/file.py
ssh: To copy entire folders, type
scp -r /path/folder username@host.com:/path/folder
note: cannot create to folders by appending them to the path of the destination
ssh: to set the name of the file that gets sent through scp, type
scp /path/file.py username@host.com:/path/folder/chosen_file_name.py
ssh: To ssh in python use
paramiko
ssh: To download something from unix command line, use
wget
html: To create a self signed ssl certificated on a server
go to home/username mkdir certificates cd certificates openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem Generating a 1024 bit RSA private key
ipython: To locate .ipython, type
ipython locate
pythonanywhere: To send my app to pythonanywhere from the shell
set up environment variables
collectstatic locally
rsync -r –delete-after project_folder/ bigintro@ssh.pythonanywhere.com:/home/bigintro/project_folder/
makemigrations and migrate in the app
ssh: To sync a local folder with a remote one while deleting extraneous files, type
rsync -r –delete-after project_folder/ bigintro@ssh.pythonanywhere.com:/home/bigintro/project_folder/
note: If there is no trailing slash, you will pass in the entire directory, and if there is you will pass in the contents
note: make sure remote app doesn’t use sqlite or it will be overwritten
git: To download a directory from github, type
git clone https://repo.git